diff --git a/cmake/Modules/CMakeDebugMessages.cmake b/cmake/Modules/CMakeDebugMessages.cmake new file mode 100644 index 000000000..b53c13d59 --- /dev/null +++ b/cmake/Modules/CMakeDebugMessages.cmake @@ -0,0 +1,71 @@ +#=============================================================================== +# @file CMakeDebugMessages.cmake +# +# @author Nicolas Richart +# +# @date creation: Thu Dec 20 2012 +# @date last modification: Fri Jan 04 2013 +# +# @brief Debug message helper +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +if(__CMAKE_DEBUG_MESSAGES) + return() +endif() +set(__CMAKE_DEBUG_MESSAGES TRUE) + +macro(cmake_register_debug_message_module module) + set(_CMAKE_DEBUG_MESSAGE_MODULES ${CMAKE_DEBUG_MESSAGE_MODULES}) + list(APPEND _CMAKE_DEBUG_MESSAGE_MODULES ${module}) + set(CMAKE_DEBUG_MESSAGE_MODULES "${_CMAKE_DEBUG_MESSAGE_MODULES}" + CACHE INTERNAL "List of modules handled by the debug messages system" FORCE) +endmacro() + +macro(cmake_activate_debug_message) + set(_default FALSE) + if(ARGC EQUAL 0) + set(_default TRUE) + endif() + + foreach(_module ${CMAKE_DEBUG_MESSAGE_MODULES}) + set(CMAKE_DEBUG_MESSAGE_${_module} ${_default} CACHE INTERNAL "" FORCE) + endforeach() + + foreach(_module ${ARGN}) + set(CMAKE_DEBUG_MESSAGE_${_module} TRUE CACHE INTERNAL "" FORCE) + endforeach() +endmacro() + + +macro(cmake_deactivate_debug_message) + foreach(_module ${CMAKE_DEBUG_MESSAGE_MODULES}) + if(CMAKE_DEBUG_MESSAGE_${_module}) + set(CMAKE_DEBUG_MESSAGE_${_module} FALSE CACHE INTERNAL "" FORCE) + endif() + endforeach() +endmacro() + +macro(cmake_debug_message module) + if(CMAKE_DEBUG_MESSAGE_${module}) + message("${PROJECT_NAME} - ${module}: ${ARGN}") + endif() +endmacro() \ No newline at end of file diff --git a/cmake/Modules/CMakeDetermineCCompiler.cmake b/cmake/Modules/CMakeDetermineCCompiler.cmake new file mode 100644 index 000000000..1c4fbc864 --- /dev/null +++ b/cmake/Modules/CMakeDetermineCCompiler.cmake @@ -0,0 +1,66 @@ +#=============================================================================== +# @file AkantuDetermineCCompiler.cmake +# +# @author Nicolas Richart +# +# @date Thu Aug 02 10:34:06 2012 +# +# @brief CMake file to determine the compiler +# +# @section LICENSE +# +# Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +macro(determine_compiler_version COMPILER) + exec_program(${CMAKE_CXX_COMPILER} + ARGS --version + OUTPUT_VARIABLE _temp + ) + + set(${COMPILER}_COMPILER_VERSION "" CACHE STRING "Vesion of ${COMPILER} compiler.") + string(REGEX MATCH "([0-9\\.]+)" + ${COMPILER}_COMPILER_VERSION + ${_temp} + ) + + mark_as_advanced(${COMPILER}_COMPILER_VERSION) +endmacro() + +# Code from James Bigler (http://www.cmake.org/pipermail/cmake/2007-June/014460.html) +set(MANTA_COMPILER_NAME_REGEXPR "icc.*$") +if(NOT CMAKE_COMPILER_IS_GNUCC) + # This regular expression also matches things like icc-9.1 + if(CMAKE_C_COMPILER MATCHES ${MANTA_COMPILER_NAME_REGEXPR}) + set(AKANTU_USING_ICC TRUE) + endif(CMAKE_C_COMPILER MATCHES ${MANTA_COMPILER_NAME_REGEXPR}) +else(NOT CMAKE_COMPILER_IS_GNUCC) + set(AKANTU_USING_GNUCC TRUE) +endif(NOT CMAKE_COMPILER_IS_GNUCC) + +set(MANTA_COMPILER_NAME_REGEXPR "icpc.*$") +if(NOT CMAKE_COMPILER_IS_GNUCXX) + if(CMAKE_CXX_COMPILER MATCHES ${MANTA_COMPILER_NAME_REGEXPR}) + set(AKANTU_USING_ICPC TRUE) + determine_compiler_version(INTEL) + #else mvsc/clang/ibm/... ? + endif(CMAKE_CXX_COMPILER MATCHES ${MANTA_COMPILER_NAME_REGEXPR}) +else(NOT CMAKE_COMPILER_IS_GNUCXX) + set(AKANTU_USING_GNUCXX TRUE) + determine_compiler_version(GCC) +endif(NOT CMAKE_COMPILER_IS_GNUCXX) diff --git a/cmake/Modules/CMakeDetermineCompiler.cmake b/cmake/Modules/CMakeDetermineCompiler.cmake new file mode 100644 index 000000000..8bbdbc04c --- /dev/null +++ b/cmake/Modules/CMakeDetermineCompiler.cmake @@ -0,0 +1,87 @@ +# not present in CMake <=2.8.7 so local copy to correct the problem for cpp-array + + +#============================================================================= +# Copyright 2004-2012 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +macro(_cmake_find_compiler lang) + # Use already-enabled languages for reference. + get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES) + list(REMOVE_ITEM _languages "${lang}") + + if(CMAKE_${lang}_COMPILER_INIT) + # Search only for the specified compiler. + set(CMAKE_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_INIT}") + else() + # Re-order the compiler list with preferred vendors first. + set(_${lang}_COMPILER_LIST "${CMAKE_${lang}_COMPILER_LIST}") + set(CMAKE_${lang}_COMPILER_LIST "") + # Prefer vendors of compilers from reference languages. + foreach(l ${_languages}) + list(APPEND CMAKE_${lang}_COMPILER_LIST + ${_${lang}_COMPILER_NAMES_${CMAKE_${l}_COMPILER_ID}}) + endforeach() + # Prefer vendors based on the platform. + list(APPEND CMAKE_${lang}_COMPILER_LIST ${CMAKE_${lang}_COMPILER_NAMES}) + # Append the rest of the list and remove duplicates. + list(APPEND CMAKE_${lang}_COMPILER_LIST ${_${lang}_COMPILER_LIST}) + unset(_${lang}_COMPILER_LIST) + list(REMOVE_DUPLICATES CMAKE_${lang}_COMPILER_LIST) + if(CMAKE_${lang}_COMPILER_EXCLUDE) + list(REMOVE_ITEM CMAKE_${lang}_COMPILER_LIST + ${CMAKE_${lang}_COMPILER_EXCLUDE}) + endif() + endif() + + # Look for directories containing compilers of reference languages. + set(_${lang}_COMPILER_HINTS) + foreach(l ${_languages}) + if(CMAKE_${l}_COMPILER AND IS_ABSOLUTE "${CMAKE_${l}_COMPILER}") + get_filename_component(_hint "${CMAKE_${l}_COMPILER}" PATH) + if(IS_DIRECTORY "${_hint}") + list(APPEND _${lang}_COMPILER_HINTS "${_hint}") + endif() + unset(_hint) + endif() + endforeach() + + # Find the compiler. + if(_${lang}_COMPILER_HINTS) + # Prefer directories containing compilers of reference languages. + list(REMOVE_DUPLICATES _${lang}_COMPILER_HINTS) + find_program(CMAKE_${lang}_COMPILER + NAMES ${CMAKE_${lang}_COMPILER_LIST} + PATHS ${_${lang}_COMPILER_HINTS} + NO_DEFAULT_PATH + DOC "${lang} compiler") + endif() + find_program(CMAKE_${lang}_COMPILER NAMES ${CMAKE_${lang}_COMPILER_LIST} DOC "${lang} compiler") + if(CMAKE_${lang}_COMPILER_INIT AND NOT CMAKE_${lang}_COMPILER) + set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_INIT}" CACHE FILEPATH "${lang} compiler" FORCE) + endif() + unset(_${lang}_COMPILER_HINTS) + unset(_languages) + + # Look for a make tool provided by Xcode + if(CMAKE_${lang}_COMPILER STREQUAL "CMAKE_${lang}_COMPILER-NOTFOUND" AND CMAKE_HOST_APPLE) + foreach(comp ${CMAKE_${lang}_COMPILER_LIST}) + execute_process(COMMAND xcrun --find ${comp} + OUTPUT_VARIABLE _xcrun_out OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE _xcrun_err) + if(_xcrun_out) + set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${_xcrun_out}") + break() + endif() + endforeach() + endif() +endmacro() diff --git a/cmake/Modules/CMakeFlagsHandling.cmake b/cmake/Modules/CMakeFlagsHandling.cmake new file mode 100644 index 000000000..508c3860b --- /dev/null +++ b/cmake/Modules/CMakeFlagsHandling.cmake @@ -0,0 +1,69 @@ +#=============================================================================== +# @file CMakeFlagsHandling.cmake +# +# @author Nicolas Richart +# +# @date creation: Thu Dec 20 2012 +# @date last modification: Tue Feb 26 2013 +# +# @brief Set of macros used by akantu to handle the package system +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +if(_CMAKE_FLAGS_HANDLING) + return() +endif() +set(_CMAKE_FLAGS_HANDLING TRUE) + + +#=============================================================================== +# Compilation options handling +#=============================================================================== +macro(_get_flags_message type desc) + if(${type} MATCHES "C..") + set(${desc} "Flags used by the compiler during all build types.") + elseif(${type} MATCHES "EXE_LINKER") + set(${desc} "Flags used by the linker.") + elseif(${type} MATCHES "SHARED_LINKER") + set(${desc} "Flags used by the linker during the creation of dll's.") + endif() +endmacro() + +#=============================================================================== +macro(add_flags type flag) + string(TOUPPER ${type} _type) + set(_var CMAKE_${_type}_FLAGS) + _get_flags_message(${_type} _desc) + string(REPLACE "${flag}" "match" _temp_var "${${_var}}") + if(NOT _temp_var MATCHES "match") + set(${_var} "${flag} ${${_var}}" CACHE STRING ${_desc} FORCE) + endif() +endmacro() + +#=============================================================================== +macro(remove_flags type flag) + string(TOUPPER ${type} _type) + set(_var CMAKE_${_type}_FLAGS) + _get_flags_message(${_type} _desc) + string(REPLACE "${flag} " "" ${_var} "${${_var}}") + set(${_var} "${${_var}}" CACHE STRING ${_desc} FORCE) +endmacro() +#=============================================================================== diff --git a/cmake/Modules/CMakePackagesSystem.cmake b/cmake/Modules/CMakePackagesSystem.cmake new file mode 100644 index 000000000..461d03656 --- /dev/null +++ b/cmake/Modules/CMakePackagesSystem.cmake @@ -0,0 +1,413 @@ +#=============================================================================== +# @file CMakePackagesSystem.cmake +# +# @author Guillaume Anciaux +# @author Nicolas Richart +# +# @date creation: Thu Dec 20 2012 +# @date last modification: Wed Sep 10 2014 +# +# @brief Set of macros used by akantu to handle the package system +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +include(CMakeParseArguments) +#=============================================================================== +# Package Management +#=============================================================================== +if(__CMAKE_PACKAGES_SYSTEM) + return() +endif() +set(__CMAKE_PACKAGES_SYSTEM TRUE) + +include(CMakeDebugMessages) +cmake_register_debug_message_module(PackagesSystem) + +macro(package_pkg_name PKG PKG_NAME) + string(TOUPPER ${PROJECT_NAME} _project) + string(TOUPPER ${PKG} _u_package) + set(${PKG_NAME} ${_project}_${_u_package}) +endmacro() + +macro(package_opt_name PKG OPT_NAME) + string(TOUPPER ${PROJECT_NAME} _project) + string(TOUPPER ${PKG} _u_package) + set(${OPT_NAME} ${_project}_USE_${_u_package}) +endmacro() + +macro(package_nature PKG NATURE) + string(TOUPPER ${PROJECT_NAME} _project) + string(TOUPPER ${PKG} _u_package) + set(${NATURE} ${_project}_${_u_package}_NATURE) +endmacro() + +macro(package_desc_name PKG DESC_NAME) + string(TOUPPER ${PROJECT_NAME} _project) + string(TOUPPER ${PKG} _u_package) + set(${DESC_NAME} ${_project}_DESC_${_u_package}) +endmacro() + +#=============================================================================== +option(AUTO_MOVE_OLD_FILES "give cmake permission to move the unregistered files to ${PROJECT_SOURCE_DIR}/tmp directory" FALSE) +mark_as_advanced(AUTO_MOVE_OLD_FILES) + +macro(add_all_packages package_dir src_dir) + string(TOUPPER ${PROJECT_NAME} _project) + cmake_debug_message(PackagesSystem "add_all_packages: PKG DIR : ${package_dir}") + file(GLOB ${_project}_package_list "${package_dir}/*.cmake") + + set(_${_project}_src_dir ${src_dir}) + + set(_package_files) + foreach(_pkg ${${_project}_package_list}) + get_filename_component(_basename ${_pkg} NAME) + list(APPEND _package_files ${_basename}) + endforeach() + + if(_package_files) + list(SORT _package_files) + endif() + + set(${_project}_PACKAGE_SYSTEM_PACKAGES_NAMES_LIST_ALL) + foreach(_pkg ${_package_files}) + string(REGEX REPLACE "[0-9]+_" "" _pkg_name ${_pkg}) + string(REGEX REPLACE "\\.cmake" "" _option_name ${_pkg_name}) + string(TOUPPER "${_option_name}" _option_name) + set(${_project}_${_option_name}_FILE ${_pkg} CACHE INTERNAL "" FORCE) + list(APPEND ${_project}_PACKAGE_SYSTEM_PACKAGES_NAMES_LIST_ALL ${_option_name}) + endforeach() + + cmake_debug_message(PackagesSystem "add_all_packages: PKG LIST : ${${_project}_PACKAGE_SYSTEM_PACKAGES_NAMES_LIST_ALL}") + +# message("Packages: ${${_project}_PACKAGE_SYSTEM_PACKAGES_NAMES_LIST_ALL}") + + foreach(_pkg ${${_project}_PACKAGE_SYSTEM_PACKAGES_NAMES_LIST_ALL}) + cmake_debug_message(PackagesSystem "add_all_packages: including ${_pkg}") + string(TOLOWER "${_pkg}" _l_pkg) + include(${package_dir}/${${_project}_${_pkg}_FILE}) + package_pkg_name(${_l_pkg} _package_name) + if (${_package_name}) + list(APPEND ${_project}_PACKAGE_SYSTEM_PACKAGES_ON ${_l_pkg}) + list(APPEND ${_project}_PACKAGE_LIST ${_pkg}) + else (${_package_name}) + list(APPEND ${_project}_PACKAGE_SYSTEM_PACKAGES_OFF ${_l_pkg}) + endif() + + foreach(_file ${${_package_name}_FILES}) + list(APPEND ${_project}_release_all_files ${_file}) + endforeach() + endforeach() + + cmake_debug_message(PackagesSystem "add_all_packages: ON PKG : ${${_project}_PACKAGE_SYSTEM_PACKAGES_ON}") + cmake_debug_message(PackagesSystem "add_all_packages: ALL RELEASE FILES LIST : ${_project}_release_all_files ${${_project}_release_all_files}") + + #check if there are some file in the release that are not registered in a package + file(GLOB_RECURSE ${_project}_all_files "*.cc" "*.hh" "*.c" "*.h" "*.hpp") + cmake_debug_message(PackagesSystem "add_all_packages: ALL FILES LIST : ${_project}_all_files ${${_project}_all_files}") + + cmake_debug_message(PackagesSystem "add_all_packages: SOURCE DIR : ${_${_project}_src_dir}") + foreach(_file ${${_project}_all_files}) + if("${_file}" MATCHES "${_${_project}_src_dir}") + file(RELATIVE_PATH __file "${_${_project}_src_dir}" ${_file}) + list(APPEND ${_project}_all_files_relatives ${__file}) + endif() + endforeach() + + foreach(_file ${${_project}_all_files_relatives}) + if(NOT ${_file} MATCHES "test.*" AND NOT ${_file} MATCHES "third-party" AND NOT ${_file} MATCHES "doc") + list(FIND ${_project}_release_all_files ${_file} _index) + if (_index EQUAL -1) + list(APPEND ${_project}_missing_files_in_packages ${_file}) + endif() + endif() + endforeach() + if (${_project}_missing_files_in_packages) + message("The files:") + message("*****************") + foreach(_file ${${_project}_missing_files_in_packages}) + message("${_file}") + endforeach() + message("*****************") + message("are not registered in any package.") + if (NOT AUTO_MOVE_OLD_FILES) + message("Please append these files in one of the packages within directory + ${PROJECT_SOURCE_DIR}/packages +or remove the files if useless. +") + message(FATAL_ERROR "abort") + else() + message("These files are getting displaced to directory ${PROJECT_SOURCE_DIR}/tmp/") + message("creating directory ${PROJECT_SOURCE_DIR}/tmp/") + file(MAKE_DIRECTORY ${PROJECT_SOURCE_DIR}/tmp/) + foreach(_file ${${_project}_missing_files_in_packages}) + get_filename_component(fname ${_file} NAME) + message("renaming ${src_dir}/${_file} to ${PROJECT_SOURCE_DIR}/tmp/${fname}") + file(RENAME ${src_dir}/${_file} ${PROJECT_SOURCE_DIR}/tmp/${fname}) + endforeach() + endif() + endif() + + if(${_project}_missing_files_in_packages) + message("A complete list of files missing in the packages description can be found here: ${PROJECT_BINARY_DIR}/missing_files_in_packages") + if(EXISTS ${PROJECT_BINARY_DIR}/missing_files_in_packages) + file(REMOVE ${PROJECT_BINARY_DIR}/missing_files_in_packages) + endif() + foreach(_file ${${_project}_missing_files_in_packages}) + file(APPEND ${PROJECT_BINARY_DIR}/missing_files_in_packages "${_file} +") + endforeach() + endif() + + #check if there are some file in the package list that are not on the current directory + foreach(_file ${${_project}_release_all_files}) + list(FIND ${_project}_all_files_relatives ${_file} _index) + if (_index EQUAL -1) + message("The file ${_file} is registered in packages but is not present in the source directory.") + endif() + endforeach() + + #construct list of files for unactivated packages +# list(APPEND _tmp_${_project}_EXCLUDE_SOURCE_FILES ${${_project}_EXCLUDE_SOURCE_FILES}) + set(_tmp_${_project}_EXCLUDE_SOURCE_FILES "") + foreach(_pkg ${${_project}_PACKAGE_SYSTEM_PACKAGES_OFF}) + package_pkg_name(${_pkg} _pkg_name) + cmake_debug_message(PackagesSystem "add_all_packages: exlude ${_file}") + list(APPEND _tmp_${_project}_EXCLUDE_SOURCE_FILES ${${_pkg_name}_FILES}) + endforeach() + + set(${_project}_EXCLUDE_SOURCE_FILES "${_tmp_${_project}_EXCLUDE_SOURCE_FILES}" CACHE INTERNAL "File to exclude in the project ${_project} package" FORCE) + #check dependencies + foreach(_pkg ${${_project}_PACKAGE_SYSTEM_PACKAGES_OFF}) + # differentiate the file types + cmake_debug_message(PackagesSystem "add_all_packages: DEPENDS PKG : ${_pkg}") + cmake_debug_message(PackagesSystem "add_all_packages: DEPENDS LST : ${${_pkg}_DEPENDS}") + package_pkg_name(${_pkg} _pkg_name) + if (NOT "${${_pkg_name}_DEB_DEPEND}" STREQUAL "") + set(deb_depend "${deb_depend}, ${${_pkg}_DEB_DEPEND}") + endif() + endforeach() + set(${_project}_PACKAGE_SYSTEM_DEBIAN_PACKAGE_DEPENDS "${deb_depend}") +endmacro() + +#=============================================================================== +macro(generate_source_list_from_packages source_dir source_files inline_files headers_files include_dirs) + string(TOUPPER ${PROJECT_NAME} _project) + + cmake_debug_message(PackagesSystem "generate_source_list_from_packages: SRC DIR : ${source_dir}") + foreach(_pkg ${${_project}_PACKAGE_SYSTEM_PACKAGES_ON}) + # differentiate the file types + package_pkg_name(${_pkg} _package_name) + cmake_debug_message(PackagesSystem "generate_source_list_from_packages: PKG ${_package_name} FILES : ${${_package_name}_FILES}") + foreach(_file ${${_package_name}_FILES}) + if(${_file} MATCHES ".*inline.*\\.cc") + list(APPEND ${_package_name}_inlines ${_file}) + elseif(${_file} MATCHES ".*\\.h+") + list(APPEND ${_package_name}_headers ${_file}) + else() + list(APPEND ${_package_name}_srcs ${_file}) + endif() + endforeach() + + # generates the include directory variable + foreach(_file ${${_package_name}_headers}) + get_filename_component(_absolute_name ${_file} ABSOLUTE) + get_filename_component(_include_dir ${_absolute_name} PATH) + list(APPEND ${_package_name}_include_dirs ${_include_dir}) + list(REMOVE_DUPLICATES ${_package_name}_include_dirs) + endforeach() + + # generate global lists for akantu to know what to build + list(APPEND ${source_files} ${${_package_name}_srcs}) + list(APPEND ${inline_files} ${${_package_name}_inlines}) + list(APPEND ${headers_files} ${${_package_name}_headers}) + list(APPEND ${include_dirs} ${${_package_name}_include_dirs}) + + cmake_debug_message(PackagesSystem "generate_source_list_from_packages: PKG ${_package_name} SRCS : ${${_package_name}_srcs}") + cmake_debug_message(PackagesSystem "generate_source_list_from_packages: PKG ${_package_name} INLINES : ${${_package_name}_inlines}") + cmake_debug_message(PackagesSystem "generate_source_list_from_packages: PKG ${_package_name} HRDS : ${${_package_name}_headers}") + cmake_debug_message(PackagesSystem "generate_source_list_from_packages: PKG ${_package_name} INCS : ${${_package_name}_include_dirs}") + endforeach() + + cmake_debug_message(PackagesSystem "generate_source_list_from_packages: SRCS : ${${source_files}}") + cmake_debug_message(PackagesSystem "generate_source_list_from_packages: HRDS : ${${headers_files}}") + cmake_debug_message(PackagesSystem "generate_source_list_from_packages: INCS : ${${include_dirs}}") +endmacro() + +#=============================================================================== +# macro to include optional packages +macro(add_optional_external_package PACKAGE DESC DEFAULT) + package_opt_name (${PACKAGE} _option_name) + package_desc_name(${PACKAGE} _desc_name) + set(${_desc_name} ${DESC}) + package_nature(${PACKAGE} _nature) + set(${_nature} "external_optional") + option(${_option_name} ${DESC} ${DEFAULT}) + _add_external_package(${PACKAGE} ${ARGN}) +endmacro() + +macro(add_external_package PACKAGE) + package_opt_name (${PACKAGE} _option_name) + set(${_option_name} ON) + package_nature(${PACKAGE} _nature) + set(${_nature} "external") + _add_external_package(${PACKAGE} ${ARGN}) +endmacro() + + +macro(_add_external_package PACKAGE) + string(TOUPPER ${PROJECT_NAME} _project) + cmake_parse_arguments(_opt_pkg "" "LANGUAGE" "DEPENDS;PREFIX;FOUND;ARGS" ${ARGN}) + + package_pkg_name (${PACKAGE} _pkg_name) + package_opt_name (${PACKAGE} _option_name) + + cmake_debug_message(PackagesSystem "add_optional_package: Registering ${PACKAGE} ${DESC} -> ${_option_name}") + + if(_opt_pkg_PREFIX) + set(_package_prefix ${_opt_pkg_PREFIX}) + else() + string(TOUPPER ${PACKAGE} _u_package) + set(_package_prefix ${_u_package}) + endif() + + if(${_option_name}) + if(_opt_pkg_LANGUAGE) + foreach(_language ${_opt_pkg_LANGUAGE}) + cmake_debug_message(PackagesSystem "add_optional_package: Package ${PACKAGE} asked for language ${_language}") + enable_language(${_language}) + endforeach() + endif() + + foreach(_dep ${_opt_pkg_DEPENDS}) + add_external_package_dependencies(${PACKAGE} ${_dep}) + endforeach() + + find_package(${PACKAGE} REQUIRED ${_opt_pkg_ARGS}) + + foreach(_prefix ${_package_prefix}) + if(${_prefix}_FOUND OR _opt_pkg_FOUND) + list(APPEND ${_project}_DEFINITIONS ${_option_name}) + if(DEFINED ${_prefix}_INCLUDE_DIRS) + list(APPEND ${_project}_EXTERNAL_LIB_INCLUDE_DIR ${${_prefix}_INCLUDE_DIRS}) + set(${_pkg_name}_INCLUDE_DIR ${${_prefix}_INCLUDE_DIRS}) + elseif(DEFINED ${_prefix}_INCLUDE_DIR) + list(APPEND ${_project}_EXTERNAL_LIB_INCLUDE_DIR ${${_prefix}_INCLUDE_DIR}) + set(${_pkg_name}_INCLUDE_DIR ${${_prefix}_INCLUDE_DIR}) + elseif(DEFINED ${_prefix}_INCLUDE_PATH) + list(APPEND ${_project}_EXTERNAL_LIB_INCLUDE_DIR ${${_prefix}_INCLUDE_PATH}) + set(${_pkg_name}_INCLUDE_DIR ${${_prefix}_INCLUDE_PATH}) + endif() + list(APPEND ${_project}_EXTERNAL_LIBRARIES ${${_prefix}_LIBRARIES}) + set(${_pkg_name}_LIBRARIES ${${_prefix}_LIBRARIES}) + set(${_pkg_name} ON) + string(TOUPPER ${PACKAGE} _u_package) + list(APPEND ${_project}_OPTION_LIST ${_u_package}) + cmake_debug_message(PackagesSystem "add_optional_package: Package ${PACKAGE} found! (PREFIX: ${_prefix})") + cmake_debug_message(PackagesSystem "add_optional_package: Package ${PACKAGE} includes : ${${_pkg_name}_INCLUDE_DIR}") + cmake_debug_message(PackagesSystem "add_optional_package: Package ${PACKAGE} libraries: ${${_pkg_name}_LIBRARIES}") + cmake_debug_message(PackagesSystem "add_optional_package: option list: ${${_project}_OPTION_LIST}") + else(${_prefix}_FOUND) + cmake_debug_message(PackagesSystem "add_optional_package: Package ${PACKAGE} not found! (PREFIX: ${_prefix})") + set(${_pkg_name} OFF) + endif() + endforeach() + endif(${_option_name}) +endmacro() + +#=============================================================================== +# macro to add meta packages +macro(add_meta_package PKG DESC DEFAULT) + cmake_debug_message(PackagesSystem "add_meta_package: register meta option ${PKG} ${DESC} ${DEFAULT}") + package_pkg_name (${PKG} _pkg_name) + package_desc_name(${PKG} _desc_name) + + set(${_desc_name} ${DESC}) + option(${_pkg_name} ${DESC} ${DEFAULT}) + + foreach(_dep ${ARGN}) + package_opt_name (${_dep} _dep_name) + mark_as_advanced(${_dep_name}) + add_external_package_dependencies(${PKG} ${_dep}) + endforeach() +endmacro() + +#=============================================================================== +macro(_add_package_dependencies PKG DEP _dep_name) + package_pkg_name (${PKG} _opt_name) + package_desc_name(${DEP} _var_dep_desc) + package_pkg_name (${DEP} _dep_pkg_name) + + if (NOT ${_opt_name}_dependencies) + set(${_opt_name}_dependencies) + endif() + + list(APPEND ${_opt_name}_dependencies ${_dep_pkg_name}) + list(REMOVE_DUPLICATES ${_opt_name}_dependencies) + + set(${_opt_name}_dependencies ${${_opt_name}_dependencies} CACHE INTERNAL "List of dependencies for package ${_opt_name}" FORCE) + + cmake_debug_message(PackagesSystem "add_package_dependecies: add dependence between ${_opt_name} and ${_dep_name}") + set(_dep_desc ${_var_dep_desc}) + + cmake_debug_message(PackagesSystem "add_package_dependecies: ON dependencies of ${_dep_name} are: ${${_dep_name}_DEPS}") + cmake_debug_message(PackagesSystem "add_package_dependecies: saved value for ${_dep_name} is: ${${_dep_name}_OLD}") + if(${_opt_name}) + if("${${_dep_name}_DEPS}" STREQUAL "") + cmake_debug_message(PackagesSystem "add_package_dependecies: Save dep state ${_dep_name}:${${_dep_name}}") + set(${_dep_name}_OLD ${${_dep_name}} CACHE INTERNAL "${_dep_desc}" FORCE) + endif() + + cmake_debug_message(PackagesSystem "add_package_dependecies: force value to ON ${_dep_name}") + set(${_dep_name} ON CACHE BOOL "${_dep_desc}" FORCE) + + list(FIND ${_dep_name}_DEPS ${_opt_name} pos) + if(pos EQUAL -1) + list(APPEND ${_dep_name}_DEPS ${_opt_name}) + set(${_dep_name}_DEPS ${${_dep_name}_DEPS} CACHE INTERNAL "Dependencies ON with package ${_dep_name}" FORCE) + endif() + else() + list(LENGTH ${_dep_name}_DEPS len) + list(FIND ${_dep_name}_DEPS ${_opt_name} pos) + if((len EQUAL 1) AND (NOT pos EQUAL -1)) + cmake_debug_message(PackagesSystem "add_package_dependecies: Restore state ${_dep_name}:${${_dep_name}} (${pos})") + set(${_dep_name} ${${_dep_name}_OLD} CACHE BOOL "${_dep_desc}" FORCE) + unset(${_dep_name}_OLD CACHE) + endif() + + if(NOT pos EQUAL -1) + list(REMOVE_AT ${_dep_name}_DEPS ${pos}) + set(${_dep_name}_DEPS ${${_dep_name}_DEPS} CACHE INTERNAL "Nb dependencies with package ${_dep_name}" FORCE) + endif() + endif() + +endmacro() + +#=============================================================================== +macro(add_internal_package_dependencies PKG DEP) + package_pkg_name (${DEP} _dep_name) + _add_package_dependencies(${PKG} ${DEP} ${_dep_name}) +endmacro() + +#=============================================================================== +macro(add_external_package_dependencies PKG DEP) + package_opt_name (${DEP} _dep_name) + _add_package_dependencies(${PKG} ${DEP} ${_dep_name}) +endmacro() diff --git a/cmake/Modules/CMakeVersionGenerator.cmake b/cmake/Modules/CMakeVersionGenerator.cmake new file mode 100644 index 000000000..d02ee1d06 --- /dev/null +++ b/cmake/Modules/CMakeVersionGenerator.cmake @@ -0,0 +1,85 @@ +#=============================================================================== +# @file CMakeVersionGenerator.cmake +# +# @author Guillaume Anciaux +# @author Nicolas Richart +# +# @date creation: Thu Dec 20 2012 +# @date last modification: Fri Jun 13 2014 +# +# @brief Set of macros used by akantu to handle the package system +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +if(__DEFINE_PROJECT_VERSION__) + return() +endif() +set(__DEFINE_PROJECT_VERSION__ TRUE) + +macro(define_project_version) + string(TOUPPER ${PROJECT_NAME} _project) + + if(EXISTS ${PROJECT_SOURCE_DIR}/VERSION) + file(STRINGS ${PROJECT_SOURCE_DIR}/VERSION ${_project}_VERSION) + + if("${${_project}_VERSION}" MATCHES "^([0-9]+)") + string(REGEX REPLACE "^([0-9]+).*" "\\1" _ver_major "${${_project}_VERSION}") + set(${_project}_MAJOR_VERSION ${_ver_major}) + + if("${${_project}_VERSION}" MATCHES "^${_ver_major}\\.([0-9]+)") + string(REGEX REPLACE "^${_ver_major}\\.([0-9]+).*" "\\1" _ver_minor "${${_project}_VERSION}") + set(${_project}_MINOR_VERSION ${_ver_minor}) + if("${${_project}_VERSION}" MATCHES "^${_ver_major}\\.${_ver_minor}\\.([0-9a-zA-Z\\-]+)") + string(REGEX REPLACE "^${_ver_major}\\.${_ver_minor}\\.([0-9a-zA-Z\\-]+).*" "\\1" _ver_build "${${_project}_VERSION}") + set(${_project}_BUILD_VERSION ${_ver_build}) + endif() + endif() + endif() + else() + find_package(Subversion) + + if(SUBVERSION_FOUND) + subversion_wc_info(${PROJECT_SOURCE_DIR} ${_project} ERROR_QUIET) + if(${${_project}_WC_FOUND}) + set(${_project}_BUILD_VERSION ${${_project}_WC_REVISION}) + set(${_project}_VERSION + "${${_project}_MAJOR_VERSION}.${${_project}_MINOR_VERSION}.${${_project}_BUILD_VERSION}" + ) + endif() + endif() + endif() + + if(NOT ${_project}_VERSION) + set(${_project}_VERSION + "${${_project}_MAJOR_VERSION}.${${_project}_MINOR_VERSION}" + ) + endif() + + # Append the library version information to the library target properties + if(NOT ${_project}_NO_LIBRARY_VERSION) + message(STATUS "${PROJECT_NAME} version: ${${_project}_VERSION}") + + set(${_project}_LIBRARY_PROPERTIES ${${_project}_LIBRARY_PROPERTIES} + VERSION "${${_project}_VERSION}" + SOVERSION "${${_project}_MAJOR_VERSION}.${${_project}_MINOR_VERSION}" + ) + endif() +endmacro() \ No newline at end of file diff --git a/cmake/Modules/CorrectWindowsPaths.cmake b/cmake/Modules/CorrectWindowsPaths.cmake new file mode 100644 index 000000000..09bcdd67d --- /dev/null +++ b/cmake/Modules/CorrectWindowsPaths.cmake @@ -0,0 +1,14 @@ +# CorrectWindowsPaths - this module defines one macro +# +# CONVERT_CYGWIN_PATH( PATH ) +# This uses the command cygpath (provided by cygwin) to convert +# unix-style paths into paths useable by cmake on windows + +macro (CONVERT_CYGWIN_PATH _path) + if (WIN32) + EXECUTE_PROCESS(COMMAND cygpath.exe -m ${${_path}} + OUTPUT_VARIABLE ${_path}) + string (STRIP ${${_path}} ${_path}) + endif (WIN32) +endmacro (CONVERT_CYGWIN_PATH) + diff --git a/cmake/Modules/FindCppArray.cmake b/cmake/Modules/FindCppArray.cmake new file mode 100644 index 000000000..34768497f --- /dev/null +++ b/cmake/Modules/FindCppArray.cmake @@ -0,0 +1,35 @@ +#=============================================================================== +# @file FindCppArray.cmake +# +# @author Alejandro M. Aragón +# +# @date creation: Fri Jan 04 2013 +# @date last modification: Thu Jan 10 2013 +# +# @brief The find_package file for cpp-array library +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +find_path (CPPARRAY_INCLUDE_DIR expr.hpp PATH_SUFFIXES array) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CppArray DEFAULT_MSG CPPARRAY_INCLUDE_DIR) + diff --git a/cmake/Modules/FindEPSN.cmake b/cmake/Modules/FindEPSN.cmake new file mode 100644 index 000000000..d252334b3 --- /dev/null +++ b/cmake/Modules/FindEPSN.cmake @@ -0,0 +1,56 @@ +#=============================================================================== +# @file FindEPSN.cmake +# +# @author Nicolas Richart +# +# @date creation: Mon Dec 13 2010 +# @date last modification: Fri Jan 04 2013 +# +# @brief The find_package file for EPSN +# +# @section LICENSE +# +# Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +#=============================================================================== +find_path(EPSN_DIR EPSNConfig.cmake + PATHS $ENV{EPSN_TOP} + ) + + +if(EPSN_DIR) + include(${EPSN_DIR}/EPSNConfig.cmake) + set(EPSN_LIB_PATH ${EPSN_DIR}/lib + ${EPSN_LIBRARIES_DIR} + ) + find_library(EPSN_COMMON_LIBRARY epsn_common + PATHS ${EPSN_LIB_PATH} + ) + find_library(EPSN_SIMULATION_LIBRARY epsn_simulation + PATHS ${EPSN_LIB_PATH} + ) + include(${EPSN_DIR}/EPSNLibraryDepends.cmake) + + set(EPSN_LIBRARIES ${EPSN_SIMULATION_LIBRARY} ${EPSN_COMMON_LIBRARY}) +endif(EPSN_DIR) + +#=============================================================================== +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(EPSN DEFAULT_MSG + EPSN_LIBRARIES EPSN_INCLUDE_DIR) diff --git a/cmake/Modules/FindFFTW.cmake b/cmake/Modules/FindFFTW.cmake new file mode 100644 index 000000000..4a86652de --- /dev/null +++ b/cmake/Modules/FindFFTW.cmake @@ -0,0 +1,72 @@ +#=============================================================================== +# @file FindFFTW.cmake +# +# @author Guillaume Anciaux +# +# @date creation: Thu Mar 17 2011 +# @date last modification: Mon Jul 28 2014 +# +# @brief +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +set(FFTW_VERSION "3" CACHE INTEGER "Version of FFTW required") + +if (FFTW_FIND_VERSION) + set(FFTW_VERSION ${FFTW_FIND_VERSION} CACHE INTEGER "Version of FFTW required") +endif() + +if (FFTW_VERSION EQUAL "2") + find_library(FFTW_LIBRARIES fftw + PATHS ${FFTW_DIR} + PATH_SUFFIXES fftw/.libs/ lib + ) + find_path(FFTW_INCLUDE_PATH fftw.h + PATHS ${FFTW_DIR} $ENV{INCLUDE_PATH} + PATH_SUFFIXES include fftw + ) +else() + + find_library(FFTW_LIBRARIES fftw3 + PATHS ENV LD_LIBRARY_PATH + ) + find_library(FFTW_THREAD_LIBRARY fftw3_threads + PATHS ENV LD_LIBRARY_PATH + ) + find_library(FFTW_OPENMP_LIBRARY fftw3_omp + PATHS ENV LD_LIBRARY_PATH + ) + find_path(FFTW_INCLUDE_PATH fftw3.h + PATHS ENV INCLUDE_PATH + PATH_SUFFIXES include fftw + ) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(FFTW DEFAULT_MSG + FFTW_LIBRARIES FFTW_INCLUDE_PATH) + + +if(NOT FFTW_FOUND) + set(FFTW_DIR "" CACHE PATH "Location of FFTW library.") +endif(NOT FFTW_FOUND) + +mark_as_advanced(FFTW_LIBRARIES FFTW_OPENMP_LIBRARY FFTW_THREAD_LIBRARY FFTW_INCLUDE_PATH FFTW_VERSION) diff --git a/cmake/Modules/FindGMSH.cmake b/cmake/Modules/FindGMSH.cmake new file mode 100644 index 000000000..0f3722fd9 --- /dev/null +++ b/cmake/Modules/FindGMSH.cmake @@ -0,0 +1,81 @@ +#=============================================================================== +# @file FindGMSH.cmake +# +# @author Nicolas Richart +# +# @date creation: Fri Oct 15 2010 +# @date last modification: Tue Sep 09 2014 +# +# @brief Find gmsh and delacre the add_mesh macro +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +find_program(GMSH gmsh + DOC "The mesh generetor gmsh") + +mark_as_advanced(GMSH) + +find_package(PackageHandleStandardArgs) +find_package_handle_standard_args(GMSH DEFAULT_MSG GMSH) + +#=============================================================================== +macro(ADD_MESH MESH_TARGET GEO_FILE DIM ORDER) + if(GMSH_FOUND) + set(arguments + ${MESH_TARGET} ${GEO_FILE} ${DIM} ${ORDER} + ${ARGN} + ) + + cmake_parse_arguments(ADD_MESH + "" + "OUTPUT" + "" + ${arguments} + ) + + set(_geo_file ${CMAKE_CURRENT_SOURCE_DIR}/${GEO_FILE}) + + if(ADD_MESH_OUTPUT) + set(_msh_file ${CMAKE_CURRENT_BINARY_DIR}/${ADD_MESH_OUTPUT}) + else(ADD_MESH_OUTPUT) + get_filename_component(_msh_file "${GEO_FILE}" NAME_WE) + set(_msh_file ${CMAKE_CURRENT_BINARY_DIR}/${_msh_file}.msh) + endif(ADD_MESH_OUTPUT) + + string(REPLACE "${CMAKE_SOURCE_DIR}/" "" _r_geo_file "${_geo_file}") + string(REPLACE "${CMAKE_BINARY_DIR}/" "" _r_msh_file "${_msh_file}") + + if(EXISTS ${_geo_file}) + add_custom_command( + OUTPUT ${_msh_file} + DEPENDS ${_geo_file} + COMMAND ${GMSH} + ARGS -${DIM} -order ${ORDER} -optimize -o ${_msh_file} ${_geo_file} 2>&1 > /dev/null + COMMENT "Generating the ${DIM}D mesh ${_r_msh_file} (order ${ORDER}) form the geometry ${_r_geo_file}" + ) + add_custom_target(${MESH_TARGET} + DEPENDS ${_msh_file}) + set_target_properties(${MESH_TARGET} PROPERTIES RESSOURCES ${_geo_file}) + #else(EXISTS ${_geo_file}) + # message("File ${_geo_file} not found") + endif(EXISTS ${_geo_file}) + endif(GMSH_FOUND) +endmacro(ADD_MESH) diff --git a/cmake/Modules/FindGSL.cmake b/cmake/Modules/FindGSL.cmake new file mode 100644 index 000000000..a2812c8b0 --- /dev/null +++ b/cmake/Modules/FindGSL.cmake @@ -0,0 +1,54 @@ +#=============================================================================== +# @file FindGSL.cmake +# +# +# @date creation: Fri Aug 10 2012 +# @date last modification: Fri Jan 04 2013 +# +# @brief +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +find_path(GSL_INCLUDE_PATH gsl_math.h + PATHS ${GSL_DIR} ENV C_INCLUDE_PATH + PATH_SUFFIXES gsl + ) + +find_library(GSL_MAIN_LIBRARY NAME gsl + PATHS ${GSL_DIR} ENV LIBRARY_PATH + PATH_SUFFIXES lib + ) + +find_library(GSL_BLAS_LIBRARY NAME gslcblas + PATHS ${GSL_DIR} ENV LIBRARY_PATH + PATH_SUFFIXES lib +) + +mark_as_advanced(GSL_INCLUDE_PATH) +mark_as_advanced(GSL_MAIN_LIBRARY NAME) +mark_as_advanced(GSL_BLAS_LIBRARY NAME) + +set(GSL_LIBRARIES ${GSL_MAIN_LIBRARY} ${GSL_BLAS_LIBRARY}) + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GSL DEFAULT_MSG + GSL_LIBRARIES GSL_INCLUDE_PATH) diff --git a/cmake/Modules/FindIOHelper.cmake b/cmake/Modules/FindIOHelper.cmake new file mode 100644 index 000000000..4eb2cf9dc --- /dev/null +++ b/cmake/Modules/FindIOHelper.cmake @@ -0,0 +1,60 @@ +#=============================================================================== +# @file FindIOHelper.cmake +# +# @author Nicolas Richart +# +# @date creation: Wed Aug 04 2010 +# @date last modification: Fri Jan 04 2013 +# +# @brief The find_package file for IOHelper +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +#=============================================================================== +#set(IOHELPER_LIBRARY "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) +find_library(IOHELPER_LIBRARY iohelper + PATHS ${IOHELPER_DIR} + PATH_SUFFIXES lib + ) + +find_path(IOHELPER_INCLUDE_DIR io_helper.hh + PATHS ${IOHELPER_DIR} + PATH_SUFFIXES include include/iohelper + ) + +#=============================================================================== +mark_as_advanced(IOHELPER_LIBRARY) +mark_as_advanced(IOHELPER_INCLUDE_DIR) + +#=============================================================================== +find_package(ZLIB REQUIRED) + +set(IOHELPER_LIBRARIES_ALL ${IOHELPER_LIBRARY} ${ZLIB_LIBRARIES}) +set(IOHELPER_LIBRARIES ${IOHELPER_LIBRARIES_ALL} CACHE INTERNAL "Libraries for IOHelper" FORCE) + +#=============================================================================== +if(NOT IOHELPER_FOUND) + set(IOHELPER_DIR "" CACHE PATH "Location of IOHelper source directory.") +endif() + +#=============================================================================== +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(IOHelper DEFAULT_MSG IOHELPER_LIBRARY IOHELPER_INCLUDE_DIR) diff --git a/cmake/Modules/FindInkscape.cmake b/cmake/Modules/FindInkscape.cmake new file mode 100644 index 000000000..eb0d2e63c --- /dev/null +++ b/cmake/Modules/FindInkscape.cmake @@ -0,0 +1,93 @@ +#=============================================================================== +# @file FindInkscape.cmake +# +# +# @date creation: Thu Jan 10 2013 +# @date last modification: Thu Jan 10 2013 +# +# @brief +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +# Module thaat checks for inkscape +# +# Sets the following variables +# +# INSCAPE: Path to inkscape to generate .png's form .svg's +# +# Provides the following functions: +# +# inkscape_generate_png_from_svg([OUTPUT_DIR ] [ ....]) +# +# Generates pngfile1, ... from svg input files pngfile1.svg, .... +# The output directory can be specified with the option OUTPUT_DIR. If it is omitted +# the files will be generated in CMAKE_CURRENT_BINARY_DIR. + +find_program(INKSCAPE inkscape DOC "Path to inkscape to generate png files from svg files") +find_program(CONVERT convert DOC "Path to convert program") +if(INKSCAPE) + set(INKSCAPE_FOUND True) +endif(INKSCAPE) + +include(CMakeParseArguments) + +function(inkscape_generate_png_from_svg) + if(NOT INKSCAPE) + return() + endif(NOT INKSCAPE) + cmake_parse_arguments(INKSCAPE "" "DPI" "" ${ARGN}) + if(NOT INKSCAPE_DPI) + set(INKSCAPE_DPI 90) + endif(NOT INKSCAPE_DPI) + + foreach(pic ${INKSCAPE_UNPARSED_ARGUMENTS}) + string(REGEX REPLACE "\\.[a-zA-Z]+" ".png" output ${pic}) + add_custom_command(OUTPUT ${output} + COMMAND ${INKSCAPE} --export-dpi=${INKSCAPE_DPI} -e ${output} -f ${pic} + DEPENDS ${pic} + COMMENT "Generating ${output} from ${pic}" + ) + endforeach(pic) +endfunction(inkscape_generate_png_from_svg) + +function(inkscape_generate_eps_from_svg) + cmake_parse_arguments(INKSCAPE "" "INPUT_DIR;OUTPUT_DIR;DPI" "" ${ARGN}) + if(NOT INKSCAPE_INPUT_DIR) + set(INKSCAPE_INPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + endif(NOT INKSCAPE_INPUT_DIR) + if(NOT INKSCAPE_INPUT_DIR) + set(INKSCAPE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) + endif(NOT INKSCAPE_INPUT_DIR) + + foreach(_pic ${INKSCAPE_UNPARSED_ARGUMENTS}) + string(REGEX REPLACE "\\.[a-zA-Z]+" ".png" input "${_pic}") + string(REGEX REPLACE "\\.[a-zA-Z]+" ".svg" svginput "${_pic}") + + add_custom_target(${input} + COMMAND ${INKSCAPE} --export-dpi=${INKSCAPE_DPI} -e ${input} ${CMAKE_CURRENT_SOURCE_DIR}/${svginput} + COMMENT "Generating ${INKSCAPE_OUTPUT_DIR}/${pic} from ${CMAKE_CURRENT_SOURCE_DIR}/${input}") + add_custom_command(OUTPUT ${_pic} + COMMAND ${CONVERT} ${INKSCAPE_INPUT_DIR}/${input} EPS:${_pic} + DEPENDS ${input} + COMMENT "Converting ${INKSCAPE_INPUT_DIR}/${input} to ${INKSCAPE_OUTPUT_DIR}/${_pic}" + WORKING_DIRECTORY ${INKSCAPE_OUTPUT_DIR}) + endforeach(_pic ${INKSCAPE_UNPARSED_ARGUMENTS}) +endfunction(inkscape_generate_eps_from_svg) \ No newline at end of file diff --git a/cmake/Modules/FindLAMMPS.cmake b/cmake/Modules/FindLAMMPS.cmake new file mode 100644 index 000000000..bf16c78ee --- /dev/null +++ b/cmake/Modules/FindLAMMPS.cmake @@ -0,0 +1,68 @@ +#=============================================================================== +# @file FindLAMMPS.cmake +# +# +# @date creation: Thu Mar 17 2011 +# @date last modification: Fri Jan 04 2013 +# +# @brief +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +find_path(LAMMPS_INCLUDE_PATH lammps.h + PATHS ${LAMMPS_DIR} ENV C_INCLUDE_PATH + PATH_SUFFIXES src + ) + +#if (not ${LAMMPS_ARCH}) + file(GLOB ARCHS "${LAMMPS_INCLUDE_PATH}/liblmp*") + foreach(loop_var IN ITEMS ${ARCHS}) + get_filename_component(loop_var ${loop_var} NAME) + string(REGEX REPLACE ".so" "" loop_var ${loop_var}) + string(REGEX REPLACE "liblmp_" "" loop_var ${loop_var}) +# MESSAGE ("possible archs compiled for lammps : ${loop_var}") + SET(LAMMPS_ARCH ${loop_var} CACHE INTERNAL "internal built version of lammps detection" FORCE) +# MESSAGE ("libname : lmp_${LAMMPS_ARCH}") + endforeach(loop_var) +#endif(not ${LAMMPS_ARCH}) + + +find_library(LAMMPS_MAIN_LIBRARY NAME lmp_${LAMMPS_ARCH} + PATHS ${LAMMPS_DIR} + PATH_SUFFIXES src + ) + +if (NOT LAMMPS_MAIN_LIBRARY) +set(LAMMPS_DIR "" CACHE PATH "Location of LAMMPS library.") +endif (NOT LAMMPS_MAIN_LIBRARY) + +find_library(LAMMPS_MEAM_LIBRARIES NAME meam + PATHS ${LAMMPS_DIR} + PATH_SUFFIXES lib/meam +) + +set(LAMMPS_LIBRARIES ${LAMMPS_MAIN_LIBRARY} ${LAMMPS_MEAM_LIBRARIES}) +SEPARATE_ARGUMENTS(LAMMPS_LIBRARIES) + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LAMMPS DEFAULT_MSG + LAMMPS_LIBRARIES LAMMPS_INCLUDE_PATH) \ No newline at end of file diff --git a/cmake/Modules/FindMumps.cmake b/cmake/Modules/FindMumps.cmake new file mode 100644 index 000000000..d5e2293fd --- /dev/null +++ b/cmake/Modules/FindMumps.cmake @@ -0,0 +1,112 @@ +#=============================================================================== +# @file FindMumps.cmake +# +# @author Nicolas Richart +# +# @date creation: Mon Dec 13 2010 +# @date last modification: Tue Sep 09 2014 +# +# @brief The find_package file for the Mumps solver +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +#=============================================================================== +if(NOT MUMPS_TYPE) + set(MUMPS_TYPE par) +endif() + +if("${MUMPS_TYPE}" STREQUAL "seq") + set(MUMPS_PREFIX _seq) +else() + unset(MUMPS_PREFIX) +endif() + +find_library(MUMPS_LIBRARY_DMUMPS NAMES dmumps${MUMPS_PREFIX} + HINTS ${MUMPS_DIR} /usr + PATH_SUFFIXES lib + ) + +find_library(MUMPS_LIBRARY_COMMON NAMES mumps_common${MUMPS_PREFIX} + HINTS ${MUMPS_DIR} + PATH_SUFFIXES lib + ) + +find_library(MUMPS_LIBRARY_PORD NAMES pord${MUMPS_PREFIX} + HINTS ${MUMPS_DIR} + PATH_SUFFIXES lib + ) + + +find_path(MUMPS_INCLUDE_DIR dmumps_c.h + HINTS ${MUMPS_DIR} + PATH_SUFFIXES include + ) + +mark_as_advanced(MUMPS_LIBRARY_COMMON) +mark_as_advanced(MUMPS_LIBRARY_DMUMPS) +mark_as_advanced(MUMPS_LIBRARY_PORD) +mark_as_advanced(MUMPS_INCLUDE_DIR) +set(MUMPS_LIBRARIES_ALL ${MUMPS_LIBRARY_DMUMPS} ${MUMPS_LIBRARY_COMMON} ${MUMPS_LIBRARY_PORD}) + +if("${MUMPS_TYPE}" STREQUAL "par") + find_library(BLACS_LIBRARY_C NAME blacsC + HINTS ${MUMPS_DIR} PATH_SUFFIXES lib) + find_library(BLACS_LIBRARY_F77 NAME blacsF77 + HINTS ${MUMPS_DIR} PATH_SUFFIXES lib) + find_library(BLACS_LIBRARY NAME blacs + HINTS ${MUMPS_DIR} PATH_SUFFIXES lib) + find_library(SCALAPACK_LIBRARIES NAME scalapack + HINTS ${MUMPS_DIR} PATH_SUFFIXES lib) + + mark_as_advanced(BLACS_LIBRARY_C) + mark_as_advanced(BLACS_LIBRARY_F77) + mark_as_advanced(BLACS_LIBRARY) + mark_as_advanced(SCALAPACK_LIBRARY) + mark_as_advanced(SCALAPACK_LIBRARIES) + if(SCALAPACK_LIBRARY) + set(BLACS_LIBRARIES_ALL ${BLACS_LIBRARIES_ALL} ${SCALAPACK_LIBRARY}) + endif() + if(BLACS_LIBRARY_F77) + set(BLACS_LIBRARIES_ALL ${BLACS_LIBRARIES_ALL} ${BLACS_LIBRARY_F77}) + endif() + if(BLACS_LIBRARY) + set(BLACS_LIBRARIES_ALL ${BLACS_LIBRARIES_ALL} ${BLACS_LIBRARY}) + endif() + if(BLACS_LIBRARY_C) + set(BLACS_LIBRARIES_ALL ${BLACS_LIBRARIES_ALL} ${BLACS_LIBRARY_C}) + endif() + if(BLACS_LIBRARY_F77) + set(BLACS_LIBRARIES_ALL ${BLACS_LIBRARIES_ALL} ${BLACS_LIBRARY_F77}) + endif() +endif() + +set(MUMPS_LIBRARIES ${MUMPS_LIBRARIES_ALL} ${BLACS_LIBRARIES_ALL} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} CACHE INTERNAL "Libraries for MUMPS" FORCE) + + +#=============================================================================== +if(NOT MUMPS_FOUND) + set(MUMPS_DIR "" CACHE PATH "Prefix of MUMPS library.") + mark_as_advanced(MUMPS_DIR) +endif() +#=============================================================================== +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Mumps DEFAULT_MSG + MUMPS_LIBRARIES MUMPS_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/Modules/FindNLopt.cmake b/cmake/Modules/FindNLopt.cmake new file mode 100644 index 000000000..1855f4578 --- /dev/null +++ b/cmake/Modules/FindNLopt.cmake @@ -0,0 +1,54 @@ +#=============================================================================== +# @file FindNLopt.cmake +# +# @author Alejandro M. Aragón +# +# @date creation: Fri Jan 04 2013 +# @date last modification: Thu Jul 24 2014 +# +# @brief The find_package file for NLopt optimization library +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +find_library(NLOPT_LIBRARIES NAMES nlopt_cxx + PATHS ${NLOPT_DIR} ${NLOPT_INTERNAL_DIR} + PATH_SUFFIXES lib + ) + +find_path(NLOPT_INCLUDE_DIR nlopt.hpp + PATHS ${NLOPT_DIR} ${NLOPT_INTERNAL_DIR} + PATH_SUFFIXES include + ) + + + +#=============================================================================== +mark_as_advanced(NLOPT_LIBRARIES) +mark_as_advanced(NLOPT_INCLUDE_DIR) +#=============================================================================== +if(NOT NLOPT_FOUND) + set(NLOPT_DIR "" CACHE PATH "Location of NLOPT source directory.") +endif() + +#=============================================================================== +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(NLopt DEFAULT_MSG NLOPT_LIBRARIES NLOPT_INCLUDE_DIR) + diff --git a/cmake/Modules/FindPETSc.cmake b/cmake/Modules/FindPETSc.cmake new file mode 100644 index 000000000..191a76fef --- /dev/null +++ b/cmake/Modules/FindPETSc.cmake @@ -0,0 +1,345 @@ +# - Try to find PETSc +# Once done this will define +# +# PETSC_FOUND - system has PETSc +# PETSC_INCLUDES - the PETSc include directories +# PETSC_LIBRARIES - Link these to use PETSc +# PETSC_COMPILER - Compiler used by PETSc, helpful to find a compatible MPI +# PETSC_DEFINITIONS - Compiler switches for using PETSc +# PETSC_MPIEXEC - Executable for running MPI programs +# PETSC_VERSION - Version string (MAJOR.MINOR.SUBMINOR) +# +# Usage: +# find_package(PETSc COMPONENTS CXX) - required if build --with-clanguage=C++ --with-c-support=0 +# find_package(PETSc COMPONENTS C) - standard behavior of checking build using a C compiler +# find_package(PETSc) - same as above +# +# Setting these changes the behavior of the search +# PETSC_DIR - directory in which PETSc resides +# PETSC_ARCH - build architecture +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +set(PETSC_VALID_COMPONENTS + C + CXX) + +if(NOT PETSc_FIND_COMPONENTS) + set(PETSC_LANGUAGE_BINDINGS "C") +else() + # Right now, this is designed for compatability with the --with-clanguage option, so + # only allow one item in the components list. + list(LENGTH ${PETSc_FIND_COMPONENTS} components_length) + if(${components_length} GREATER 1) + message(FATAL_ERROR "Only one component for PETSc is allowed to be specified") + endif() + # This is a stub for allowing multiple components should that time ever come. Perhaps + # to also test Fortran bindings? + foreach(component ${PETSc_FIND_COMPONENTS}) + list(FIND PETSC_VALID_COMPONENTS ${component} component_location) + if(${component_location} EQUAL -1) + message(FATAL_ERROR "\"${component}\" is not a valid PETSc component.") + else() + list(APPEND PETSC_LANGUAGE_BINDINGS ${component}) + endif() + endforeach() +endif() + +function (petsc_get_version) + if (EXISTS "${PETSC_DIR}/include/petscversion.h") + file (STRINGS "${PETSC_DIR}/include/petscversion.h" vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ") + foreach (line ${vstrings}) + string (REGEX REPLACE " +" ";" fields ${line}) # break line into three fields (the first is always "#define") + list (GET fields 1 var) + list (GET fields 2 val) + set (${var} ${val} PARENT_SCOPE) + set (${var} ${val}) # Also in local scope so we have access below + endforeach () + if (PETSC_VERSION_RELEASE) + set (PETSC_VERSION "${PETSC_VERSION_MAJOR}.${PETSC_VERSION_MINOR}.${PETSC_VERSION_SUBMINOR}p${PETSC_VERSION_PATCH}" PARENT_SCOPE) + else () + # make dev version compare higher than any patch level of a released version + set (PETSC_VERSION "${PETSC_VERSION_MAJOR}.${PETSC_VERSION_MINOR}.${PETSC_VERSION_SUBMINOR}.99" PARENT_SCOPE) + endif () + else () + message (SEND_ERROR "PETSC_DIR can not be used, ${PETSC_DIR}/include/petscversion.h does not exist") + endif () +endfunction () + +find_path (PETSC_DIR include/petsc.h + HINTS ENV PETSC_DIR + PATHS + # Debian paths + /usr/lib/petscdir/3.3 /usr/lib/petscdir/3.2 /usr/lib/petscdir/3.1 + /usr/lib/petscdir/3.0.0 /usr/lib/petscdir/2.3.3 /usr/lib/petscdir/2.3.2 + $ENV{HOME}/petsc + DOC "PETSc Directory") + +find_program (MAKE_EXECUTABLE NAMES make gmake) + +if (NOT PETSC_ARCH) + if (NOT ENV{PETSC_ARCH}) + set(_petsc_arches + linux-gnu-c-debug linux-gnu-c-opt # Debian defaults + x86_64-unknown-linux-gnu i386-unknown-linux-gnu) + else() + set(_petsc_arches $ENV{PETSC_ARCH}) # If set, use environment variable first) + endif() +else() + set (_petsc_arches + ${PETSC_ARCH}) +endif() + +if (NOT PETSC_DIR) + if (NOT ENV{PETSC_DIR}) + set(PETSC_DIR /usr/lib/petsc) + else() + set(PETSC_DIR $ENV{PETSC_DIR}) # If set, use environment variable first) + endif() +endif() + +foreach (arch ${_petsc_arches}) + set (petscconf "NOTFOUND" CACHE INTERNAL "Scratch variable" FORCE) + find_path (petscconf petscconf.h + HINTS ${PETSC_DIR} + PATH_SUFFIXES ${arch}/include bmake/${arch} + NO_DEFAULT_PATH) + + if(petscconf) + set (PETSC_ARCH "${arch}" CACHE STRING "PETSc build architecture") + set(_petsc_dir ${PETSC_DIR}) + set (PETSC_DIR "${_petsc_dir}" CACHE STRING "PETSc build directory") + break() + endif() +endforeach() + +set (petsc_slaves LIBRARIES_SYS LIBRARIES_VEC LIBRARIES_MAT LIBRARIES_DM LIBRARIES_KSP LIBRARIES_SNES LIBRARIES_TS + INCLUDE_DIR INCLUDE_CONF) +include (FindPackageMultipass) +#find_package_multipass (PETSc petsc_config_current +# STATES DIR ARCH +# DEPENDENTS INCLUDES LIBRARIES COMPILER MPIEXEC EXECUTABLE_RUNS ${petsc_slaves}) +# +# Determine whether the PETSc layout is old-style (through 2.3.3) or +# new-style (>= 3.0.0) +if (EXISTS "${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h") # > 2.3.3 + set (petsc_conf_rules "${PETSC_DIR}/conf/rules") + set (petsc_conf_variables "${PETSC_DIR}/conf/variables") +elseif (EXISTS "${PETSC_DIR}/bmake/${PETSC_ARCH}/petscconf.h") # <= 2.3.3 + set (petsc_conf_rules "${PETSC_DIR}/bmake/common/rules") + set (petsc_conf_variables "${PETSC_DIR}/bmake/common/variables") +elseif (PETSC_DIR) + message (SEND_ERROR "The pair PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} do not specify a valid PETSc installation") +endif () + + +message(petsc_conf_rules ${petsc_conf_rules}) +message(petsc_conf_variables ${petsc_conf_variables}) +message(petsc_config_current ${petsc_config_current}) + + +if (petsc_conf_rules AND petsc_conf_variables AND NOT petsc_config_current) + petsc_get_version() + + # Put variables into environment since they are needed to get + # configuration (petscvariables) in the PETSc makefile + set (ENV{PETSC_DIR} "${PETSC_DIR}") + set (ENV{PETSC_ARCH} "${PETSC_ARCH}") + + # A temporary makefile to probe the PETSc configuration + set (petsc_config_makefile "${PROJECT_BINARY_DIR}/Makefile.petsc") + file (WRITE "${petsc_config_makefile}" +"## This file was autogenerated by FindPETSc.cmake +# PETSC_DIR = ${PETSC_DIR} +# PETSC_ARCH = ${PETSC_ARCH} +include ${petsc_conf_rules} +include ${petsc_conf_variables} +show : + -@echo -n \${\${VARIABLE}} +") + + macro (PETSC_GET_VARIABLE name var) + set (${var} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) + execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} show VARIABLE=${name} + OUTPUT_VARIABLE ${var} + RESULT_VARIABLE petsc_return) + endmacro (PETSC_GET_VARIABLE) + petsc_get_variable (PETSC_LIB_DIR petsc_lib_dir) + petsc_get_variable (PETSC_EXTERNAL_LIB_BASIC petsc_libs_external) + petsc_get_variable (PETSC_CCPPFLAGS petsc_cpp_line) + petsc_get_variable (PETSC_INCLUDE petsc_include) + petsc_get_variable (PCC petsc_cc) + petsc_get_variable (PCC_FLAGS petsc_cc_flags) + petsc_get_variable (MPIEXEC petsc_mpiexec) + # We are done with the temporary Makefile, calling PETSC_GET_VARIABLE after this point is invalid! + file (REMOVE ${petsc_config_makefile}) + + include (ResolveCompilerPaths) + # Extract include paths and libraries from compile command line + resolve_includes (petsc_includes_all "${petsc_cpp_line}") + + #on windows we need to make sure we're linking against the right + #runtime library + if (WIN32) + if (petsc_cc_flags MATCHES "-MT") + set(using_md False) + foreach(flag_var + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) + if(${flag_var} MATCHES "/MD") + set(using_md True) + endif(${flag_var} MATCHES "/MD") + endforeach(flag_var) + if(${using_md} MATCHES "True") + message(WARNING "PETSc was built with /MT, but /MD is currently set. + See http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F") + endif(${using_md} MATCHES "True") + endif (petsc_cc_flags MATCHES "-MT") + endif (WIN32) + + include (CorrectWindowsPaths) + convert_cygwin_path(petsc_lib_dir) + message (STATUS "petsc_lib_dir ${petsc_lib_dir}") + + macro (PETSC_FIND_LIBRARY suffix name) + set (PETSC_LIBRARY_${suffix} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # Clear any stale value, if we got here, we need to find it again + if (WIN32) + set (libname lib${name}) #windows expects "libfoo", linux expects "foo" + else (WIN32) + set (libname ${name}) + endif (WIN32) + find_library (PETSC_LIBRARY_${suffix} NAMES ${libname} HINTS ${petsc_lib_dir} NO_DEFAULT_PATH) + set (PETSC_LIBRARIES_${suffix} "${PETSC_LIBRARY_${suffix}}") + mark_as_advanced (PETSC_LIBRARY_${suffix}) + endmacro (PETSC_FIND_LIBRARY suffix name) + + # Look for petscvec first, if it doesn't exist, we must be using single-library + petsc_find_library (VEC petscvec) + if (PETSC_LIBRARY_VEC) + petsc_find_library (SYS "petscsys;petsc") # libpetscsys is called libpetsc prior to 3.1 (when single-library was introduced) + petsc_find_library (MAT petscmat) + petsc_find_library (DM petscdm) + petsc_find_library (KSP petscksp) + petsc_find_library (SNES petscsnes) + petsc_find_library (TS petscts) + macro (PETSC_JOIN libs deps) + list (APPEND PETSC_LIBRARIES_${libs} ${PETSC_LIBRARIES_${deps}}) + endmacro (PETSC_JOIN libs deps) + petsc_join (VEC SYS) + petsc_join (MAT VEC) + petsc_join (DM MAT) + petsc_join (KSP DM) + petsc_join (SNES KSP) + petsc_join (TS SNES) + petsc_join (ALL TS) + else () + set (PETSC_LIBRARY_VEC "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # There is no libpetscvec + petsc_find_library (SINGLE petsc) + foreach (pkg SYS VEC MAT DM KSP SNES TS ALL) + set (PETSC_LIBRARIES_${pkg} "${PETSC_LIBRARY_SINGLE}") + endforeach () + endif () + if (PETSC_LIBRARY_TS) + message (STATUS "Recognized PETSc install with separate libraries for each package") + else () + message (STATUS "Recognized PETSc install with single library for all packages") + endif () + + include(Check${PETSC_LANGUAGE_BINDINGS}SourceRuns) + macro (PETSC_TEST_RUNS includes libraries runs) + if(${PETSC_LANGUAGE_BINDINGS} STREQUAL "C") + set(_PETSC_ERR_FUNC "CHKERRQ(ierr)") + elseif(${PETSC_LANGUAGE_BINDINGS} STREQUAL "CXX") + set(_PETSC_ERR_FUNC "CHKERRXX(ierr)") + endif() + if (PETSC_VERSION VERSION_GREATER 3.1) + set (_PETSC_TSDestroy "TSDestroy(&ts)") + else () + set (_PETSC_TSDestroy "TSDestroy(ts)") + endif () + + set(_PETSC_TEST_SOURCE " +static const char help[] = \"PETSc test program.\"; +#include +int main(int argc,char *argv[]) { + PetscErrorCode ierr; + TS ts; + + ierr = PetscInitialize(&argc,&argv,0,help);${_PETSC_ERR_FUNC}; + ierr = TSCreate(PETSC_COMM_WORLD,&ts);${_PETSC_ERR_FUNC}; + ierr = TSSetFromOptions(ts);${_PETSC_ERR_FUNC}; + ierr = ${_PETSC_TSDestroy};${_PETSC_ERR_FUNC}; + ierr = PetscFinalize();${_PETSC_ERR_FUNC}; + return 0; +} +") + multipass_source_runs ("${includes}" "${libraries}" "${_PETSC_TEST_SOURCE}" ${runs} "${PETSC_LANGUAGE_BINDINGS}") + + if (${${runs}}) + set (PETSC_EXECUTABLE_RUNS "YES" CACHE BOOL + "Can the system successfully run a PETSc executable? This variable can be manually set to \"YES\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build. If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE) + endif (${${runs}}) + endmacro (PETSC_TEST_RUNS) + + + find_path (PETSC_INCLUDE_DIR petscts.h HINTS "${PETSC_DIR}" PATH_SUFFIXES include NO_DEFAULT_PATH) + find_path (PETSC_INCLUDE_CONF petscconf.h HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/include" "bmake/${PETSC_ARCH}" NO_DEFAULT_PATH) + mark_as_advanced (PETSC_INCLUDE_DIR PETSC_INCLUDE_CONF) + set (petsc_includes_minimal ${PETSC_INCLUDE_CONF} ${PETSC_INCLUDE_DIR}) + + petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" petsc_works_minimal) + if (petsc_works_minimal) + message (STATUS "Minimal PETSc includes and libraries work. This probably means we are building with shared libs.") + set (petsc_includes_needed "${petsc_includes_minimal}") + else (petsc_works_minimal) # Minimal includes fail, see if just adding full includes fixes it + petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_allincludes) + if (petsc_works_allincludes) # It does, we just need all the includes ( + message (STATUS "PETSc requires extra include paths, but links correctly with only interface libraries. This is an unexpected configuration (but it seems to work fine).") + set (petsc_includes_needed ${petsc_includes_all}) + else (petsc_works_allincludes) # We are going to need to link the external libs explicitly + resolve_libraries (petsc_libraries_external "${petsc_libs_external}") + foreach (pkg SYS VEC MAT DM KSP SNES TS ALL) + list (APPEND PETSC_LIBRARIES_${pkg} ${petsc_libraries_external}) + endforeach (pkg) + petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" petsc_works_alllibraries) + if (petsc_works_alllibraries) + message (STATUS "PETSc only need minimal includes, but requires explicit linking to all dependencies. This is expected when PETSc is built with static libraries.") + set (petsc_includes_needed ${petsc_includes_minimal}) + else (petsc_works_alllibraries) + # It looks like we really need everything, should have listened to Matt + set (petsc_includes_needed ${petsc_includes_all}) + petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_all) + if (petsc_works_all) # We fail anyways + message (STATUS "PETSc requires extra include paths and explicit linking to all dependencies. This probably means you have static libraries and something unexpected in PETSc headers.") + else (petsc_works_all) # We fail anyways + message (STATUS "PETSc could not be used, maybe the install is broken.") + endif (petsc_works_all) + endif (petsc_works_alllibraries) + endif (petsc_works_allincludes) + endif (petsc_works_minimal) + + # We do an out-of-source build so __FILE__ will be an absolute path, hence __INSDIR__ is superfluous + if (${PETSC_VERSION} VERSION_LESS 3.1) + set (PETSC_DEFINITIONS "-D__SDIR__=\"\"" CACHE STRING "PETSc definitions" FORCE) + else () + set (PETSC_DEFINITIONS "-D__INSDIR__=" CACHE STRING "PETSc definitions" FORCE) + endif () + # Sometimes this can be used to assist FindMPI.cmake + set (PETSC_MPIEXEC ${petsc_mpiexec} CACHE FILEPATH "Executable for running PETSc MPI programs" FORCE) + set (PETSC_INCLUDES ${petsc_includes_needed} CACHE STRING "PETSc include path" FORCE) + set (PETSC_LIBRARIES ${PETSC_LIBRARIES_ALL} CACHE STRING "PETSc libraries" FORCE) + set (PETSC_COMPILER ${petsc_cc} CACHE FILEPATH "PETSc compiler" FORCE) + # Note that we have forced values for all these choices. If you + # change these, you are telling the system to trust you that they + # work. It is likely that you will end up with a broken build. + mark_as_advanced (PETSC_INCLUDES PETSC_LIBRARIES PETSC_COMPILER PETSC_DEFINITIONS PETSC_MPIEXEC PETSC_EXECUTABLE_RUNS) +endif () + +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (PETSc + "PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH." + PETSC_INCLUDES PETSC_LIBRARIES PETSC_EXECUTABLE_RUNS) diff --git a/cmake/Modules/FindPQXX.cmake b/cmake/Modules/FindPQXX.cmake new file mode 100644 index 000000000..f5817f473 --- /dev/null +++ b/cmake/Modules/FindPQXX.cmake @@ -0,0 +1,61 @@ +#=============================================================================== +# @file FindPQXX.cmake +# +# @author Nicolas Richart +# +# @date creation: Fri Jan 13 2012 +# @date last modification: Tue Sep 09 2014 +# +# @brief The find_package file for PostgreSQL C++ library +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +find_package(PostgreSQL REQUIRED) +if(POSTGRESQL_FOUND) + find_library(PQXX_LIBRARY NAMES pqxx + HINTS ${PQXX_DIR} ENV PQXX_DIR + DOC "Location of libpqxx library" + ) + + find_path(PQXX_HEADER_DIR NAMES pqxx/pqxx + HINTS ${PQXX_DIR} ENV PQXX_DIR + DOC "Path to pqxx/pqxx header file. Do not include the 'pqxx' directory in this value." + ) + + set(PQXX_INCLUDE_DIR "${PQXX_HEADER_DIR};${POSTGRESQL_INCLUDE_DIR}" CACHE STRING "Include directories for PostgreSQL C++ library" FORCE) + set(PQXX_LIBRARIES "${PQXX_LIBRARY};${POSTGRESQL_LIBRARIES}" CACHE STRING "Link libraries for PostgreSQL C++ interface" FORCE) + + mark_as_advanced(PQXX_HEADER_DIR) + mark_as_advanced(PQXX_INCLUDE_DIR) + mark_as_advanced(PQXX_LIBRARY) + mark_as_advanced(PQXX_LIBRARIES) +endif() + +#=============================================================================== +if(NOT PQXX_FOUND) + set(PQXX_DIR "" CACHE PATH "Help to find the location of pqxx library.") + mark_as_advanced(PQXX_FOUND) +endif() + +#=============================================================================== +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PQXX DEFAULT_MSG PQXX_LIBRARY PQXX_HEADER_DIR) + diff --git a/cmake/Modules/FindPTScotch.cmake b/cmake/Modules/FindPTScotch.cmake new file mode 100644 index 000000000..0daeffc97 --- /dev/null +++ b/cmake/Modules/FindPTScotch.cmake @@ -0,0 +1,87 @@ +#=============================================================================== +# @file FindPTScotch.cmake +# +# @author Nicolas Richart +# +# @date creation: Tue Apr 05 2011 +# @date last modification: Fri Jan 04 2013 +# +# @brief The find_package file for PT-Scotch +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +#=============================================================================== +#if(PTSCOTCH_DIR) +# set(PTSCOTCH_LIBRARY "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) +#endif(PTSCOTCH_DIR) + +find_library(PTSCOTCH_LIBRARY ptscotch + PATHS ${PTSCOTCH_DIR} + PATH_SUFFIXES src/libscotch lib + ) + +find_library(PTSCOTCH_LIBRARY_ERR ptscotcherr + PATHS ${PTSCOTCH_DIR} + PATH_SUFFIXES src/libscotch lib + ) + +find_library(PTSCOTCH_LIBRARY_ESMUMPS ptesmumps + PATHS ${PTSCOTCH_DIR} + PATH_SUFFIXES src/libscotch lib + ) + +find_path(PTSCOTCH_INCLUDE_PATH ptscotch.h + PATHS ${PTSCOTCH_DIR} + PATH_SUFFIXES include scotch src/libscotch include/scotch + ) + +#=============================================================================== +mark_as_advanced(PTSCOTCH_LIBRARY) +mark_as_advanced(PTSCOTCH_LIBRARY_ERR) +mark_as_advanced(PTSCOTCH_LIBRARY_ESMUMPS) +mark_as_advanced(PTSCOTCH_INCLUDE_PATH) + +set(PTSCOTCH_LIBRARIES_ALL ${PTSCOTCH_LIBRARY} ${PTSCOTCH_LIBRARY_ERR}) + +if(PTSCOTCH_LIBRARY_ESMUMPS) + set(PTSCOTCH_LIBRARIES_ALL ${PTSCOTCH_LIBRARY_ESMUMPS} ${PTSCOTCH_LIBRARIES_ALL}) +endif() + +set(PTSCOTCH_LIBRARIES ${PTSCOTCH_LIBRARIES_ALL} CACHE INTERNAL "Libraries for PT-Scotch" FORCE) + +#=============================================================================== +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PTSCOTCH DEFAULT_MSG + PTSCOTCH_LIBRARY PTSCOTCH_LIBRARY_ERR PTSCOTCH_INCLUDE_PATH) + + +if(PTSCOTCH_INCLUDE_PATH) + file(STRINGS ${PTSCOTCH_INCLUDE_PATH}/scotch.h PTSCOTCH_INCLUDE_CONTENT) + string(REGEX MATCH "_cplusplus" _match ${PTSCOTCH_INCLUDE_CONTENT}) + if(_match) + add_definitions(-DAKANTU_PTSCOTCH_NO_EXTERN) + endif() +endif() + +#=============================================================================== +if(NOT PTSCOTCH_FOUND) + set(PTSCOTCH_DIR "" CACHE PATH "Location of PT-Scotch library.") +endif(NOT PTSCOTCH_FOUND) diff --git a/cmake/Modules/FindPackageMultipass.cmake b/cmake/Modules/FindPackageMultipass.cmake new file mode 100644 index 000000000..fa350a928 --- /dev/null +++ b/cmake/Modules/FindPackageMultipass.cmake @@ -0,0 +1,106 @@ +# PackageMultipass - this module defines two macros +# +# FIND_PACKAGE_MULTIPASS (Name CURRENT +# STATES VAR0 VAR1 ... +# DEPENDENTS DEP0 DEP1 ...) +# +# This function creates a cache entry _CURRENT which +# the user can set to "NO" to trigger a reconfiguration of the package. +# The first time this function is called, the values of +# _VAR0, ... are saved. If _CURRENT +# is false or if any STATE has changed since the last time +# FIND_PACKAGE_MULTIPASS() was called, then CURRENT will be set to "NO", +# otherwise CURRENT will be "YES". IF not CURRENT, then +# _DEP0, ... will be FORCED to NOTFOUND. +# Example: +# find_path (FOO_DIR include/foo.h) +# FIND_PACKAGE_MULTIPASS (Foo foo_current +# STATES DIR +# DEPENDENTS INCLUDES LIBRARIES) +# if (NOT foo_current) +# # Make temporary files, run programs, etc, to determine FOO_INCLUDES and FOO_LIBRARIES +# endif (NOT foo_current) +# +# MULTIPASS_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS LANGUAGE) +# Always runs the given test, use this when you need to re-run tests +# because parent variables have made old cache entries stale. The LANGUAGE +# variable is either C or CXX indicating which compiler the test should +# use. +# MULTIPASS_C_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS) +# DEPRECATED! This is only included for backwards compatability. Use +# the more general MULTIPASS_SOURCE_RUNS instead. +# Always runs the given test, use this when you need to re-run tests +# because parent variables have made old cache entries stale. + +macro (FIND_PACKAGE_MULTIPASS _name _current) + string (TOUPPER ${_name} _NAME) + set (_args ${ARGV}) + list (REMOVE_AT _args 0 1) + + set (_states_current "YES") + list (GET _args 0 _cmd) + if (_cmd STREQUAL "STATES") + list (REMOVE_AT _args 0) + list (GET _args 0 _state) + while (_state AND NOT _state STREQUAL "DEPENDENTS") + # The name of the stored value for the given state + set (_stored_var PACKAGE_MULTIPASS_${_NAME}_${_state}) + if (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}") + set (_states_current "NO") + endif (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}") + set (${_stored_var} "${${_NAME}_${_state}}" CACHE INTERNAL "Stored state for ${_name}." FORCE) + list (REMOVE_AT _args 0) + list (GET _args 0 _state) + endwhile (_state AND NOT _state STREQUAL "DEPENDENTS") + endif (_cmd STREQUAL "STATES") + + set (_stored ${_NAME}_CURRENT) + if (NOT ${_stored}) + set (${_stored} "YES" CACHE BOOL "Is the configuration for ${_name} current? Set to \"NO\" to reconfigure." FORCE) + set (_states_current "NO") + endif (NOT ${_stored}) + + set (${_current} ${_states_current}) + if (NOT ${_current} AND PACKAGE_MULTIPASS_${_name}_CALLED) + message (STATUS "Clearing ${_name} dependent variables") + # Clear all the dependent variables so that the module can reset them + list (GET _args 0 _cmd) + if (_cmd STREQUAL "DEPENDENTS") + list (REMOVE_AT _args 0) + foreach (dep ${_args}) + set (${_NAME}_${dep} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) + endforeach (dep) + endif (_cmd STREQUAL "DEPENDENTS") + set (${_NAME}_FOUND "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) + endif () + set (PACKAGE_MULTIPASS_${name}_CALLED YES CACHE INTERNAL "Private" FORCE) +endmacro (FIND_PACKAGE_MULTIPASS) + + +macro (MULTIPASS_SOURCE_RUNS includes libraries source runs language) + include (Check${language}SourceRuns) + # This is a ridiculous hack. CHECK_${language}_SOURCE_* thinks that if the + # *name* of the return variable doesn't change, then the test does + # not need to be re-run. We keep an internal count which we + # increment to guarantee that every test name is unique. If we've + # gotten here, then the configuration has changed enough that the + # test *needs* to be rerun. + if (NOT MULTIPASS_TEST_COUNT) + set (MULTIPASS_TEST_COUNT 00) + endif (NOT MULTIPASS_TEST_COUNT) + math (EXPR _tmp "${MULTIPASS_TEST_COUNT} + 1") # Why can't I add to a cache variable? + set (MULTIPASS_TEST_COUNT ${_tmp} CACHE INTERNAL "Unique test ID") + set (testname MULTIPASS_TEST_${MULTIPASS_TEST_COUNT}_${runs}) + set (CMAKE_REQUIRED_INCLUDES ${includes}) + set (CMAKE_REQUIRED_LIBRARIES ${libraries}) + if(${language} STREQUAL "C") + check_c_source_runs ("${source}" ${testname}) + elseif(${language} STREQUAL "CXX") + check_cxx_source_runs ("${source}" ${testname}) + endif() + set (${runs} "${${testname}}") +endmacro (MULTIPASS_SOURCE_RUNS) + +macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs) + multipass_source_runs("${includes}" "${libraries}" "${source}" ${runs} "C") +endmacro (MULTIPASS_C_SOURCE_RUNS) diff --git a/cmake/Modules/FindParaDiS.cmake b/cmake/Modules/FindParaDiS.cmake new file mode 100644 index 000000000..4ffeb0aee --- /dev/null +++ b/cmake/Modules/FindParaDiS.cmake @@ -0,0 +1,45 @@ +#=============================================================================== +# @file FindParaDiS.cmake +# +# +# @date creation: Tue Mar 29 2011 +# @date last modification: Fri Jan 04 2013 +# +# @brief +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +find_library(PARADIS_LIBRARIES paradis + PATHS ${PARADIS_DIR} + PATH_SUFFIXES bin) + +find_path(PARADIS_INCLUDE_PATH ParadisGen.h + PATHS ${PARADIS_DIR} + PATH_SUFFIXES include +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PARADIS DEFAULT_MSG + PARADIS_LIBRARIES PARADIS_INCLUDE_PATH) + +if (NOT PARADIS_FOUND) + set(PARADIS_DIR "" CACHE PATH "Location of PARADIS library") +endif(NOT PARADIS_FOUND) \ No newline at end of file diff --git a/cmake/Modules/FindPostgreSQL.cmake b/cmake/Modules/FindPostgreSQL.cmake new file mode 100644 index 000000000..7821f67eb --- /dev/null +++ b/cmake/Modules/FindPostgreSQL.cmake @@ -0,0 +1,46 @@ +#=============================================================================== +# @file FindPostgreSQL.cmake +# +# @author Nicolas Richart +# +# @date creation: Fri Jan 13 2012 +# @date last modification: Thu Nov 14 2013 +# +# @brief The find_package file for PostgreSQL C library +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +find_library(POSTGRESQL_LIBRARIES NAMES pq + PATH_SUFFIXES pgsql postgresql + PATH ENV POSTGRESQL_DIR + ) + +find_path(POSTGRESQL_INCLUDE_DIR NAMES libpq-fe.h + PATH_SUFFIXES pgsql postgresql + PATHS ENV POSTGRESQL_DIR + ) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(POSTGRESQL DEFAULT_MSG + POSTGRESQL_LIBRARIES POSTGRESQL_INCLUDE_DIR) + +mark_as_advanced(POSTGRESQL_INCLUDE_DIR) +mark_as_advanced(POSTGRESQL_LIBRARIES) diff --git a/cmake/Modules/FindQVIEW.cmake b/cmake/Modules/FindQVIEW.cmake new file mode 100644 index 000000000..461bd7de4 --- /dev/null +++ b/cmake/Modules/FindQVIEW.cmake @@ -0,0 +1,50 @@ +#=============================================================================== +# @file FindQVIEW.cmake +# +# @author Guillaume Anciaux +# @author Nicolas Richart +# +# @date creation: Thu Mar 17 2011 +# @date last modification: Sun Jan 06 2013 +# +# @brief The find_package file for libQVIEW +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +find_library(QVIEW_LIBRARIES NAME qview + PATHS ${QVIEW_DIR} + PATH_SUFFIXES lib + ) +#=============================================================================== +find_path(QVIEW_INCLUDE_DIR libqview.h + PATHS ${QVIEW_DIR} + PATH_SUFFIXES include src + ) +#=============================================================================== +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(QVIEW DEFAULT_MSG + QVIEW_LIBRARIES QVIEW_INCLUDE_DIR) + +#=============================================================================== +if(NOT QVIEW_FOUND) + set(QVIEW_DIR "" CACHE PATH "Location of QVIEW library.") +endif(NOT QVIEW_FOUND) + diff --git a/cmake/Modules/FindSIMULPACK.cmake b/cmake/Modules/FindSIMULPACK.cmake new file mode 100644 index 000000000..c28e68bf3 --- /dev/null +++ b/cmake/Modules/FindSIMULPACK.cmake @@ -0,0 +1,118 @@ +#=============================================================================== +# @file FindSIMULPACK.cmake +# +# +# @date creation: Thu Mar 17 2011 +# @date last modification: Fri Jan 04 2013 +# +# @brief +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +find_path(SIMULPACK_INCLUDE_PATH adlib.h + PATHS ${SIMULPACK_DIR} ENV C_INCLUDE_PATH + PATH_SUFFIXES include src adlib adlib-cmake + ) + +SET(USING_SIMULPACK_TEMPERATURE OFF CACHE BOOL "Activation of temperature within SIMULPACK plugin" ) + +SET(SIMULPACK_MATERIALS "-NOTFOUND" CACHE LIBRARY "" FORCE) +SET(SIMULPACK_MECHANICS "-NOTFOUND" CACHE LIBRARY "" FORCE) +SET(SIMULPACK_MESHER3D "-NOTFOUND" CACHE LIBRARY "" FORCE) +SET(SIMULPACK_UTILS "-NOTFOUND" CACHE LIBRARY "" FORCE) +SET(SIMULPACK_FEM "-NOTFOUND" CACHE LIBRARY "" FORCE) +SET(SIMULPACK_LIBMYUTILS "-NOTFOUND" CACHE LIBRARY "" FORCE) +SET(SIMULPACK_SUBDI_COLLAPSE3D "-NOTFOUND" CACHE LIBRARY "" FORCE) +SET(SIMULPACK_MESH_IO "-NOTFOUND" CACHE LIBRARY "" FORCE) + + +FIND_LIBRARY(SIMULPACK_PMECHANICS NAME pmechanics + PATHS ${SIMULPACK_DIR} + PATHS ${SIMULPACK_LIB_PATH} + PATH_SUFFIXES lib + ) +FIND_LIBRARY(SIMULPACK_MESHER3D NAME mesher3d + PATHS ${SIMULPACK_DIR} + PATHS ${SIMULPACK_LIB_PATH} + PATH_SUFFIXES lib + ) +FIND_LIBRARY(SIMULPACK_MATERIALS NAME materials + PATHS ${SIMULPACK_DIR} + PATHS ${SIMULPACK_LIB_PATH} + PATH_SUFFIXES lib + ) +FIND_LIBRARY(SIMULPACK_MECHANICS NAME mechanics + PATHS ${SIMULPACK_DIR} + PATHS ${SIMULPACK_LIB_PATH} + PATH_SUFFIXES lib + ) +FIND_LIBRARY(SIMULPACK_FEM NAME fem + PATHS ${SIMULPACK_DIR} + PATHS ${SIMULPACK_LIB_PATH} + PATH_SUFFIXES lib + ) +FIND_LIBRARY(SIMULPACK_MYUTILS NAME myutils + PATHS ${SIMULPACK_DIR} + PATHS ${SIMULPACK_LIB_PATH} + PATH_SUFFIXES lib + ) +FIND_LIBRARY(SIMULPACK_UTILS NAME utils + PATHS ${SIMULPACK_DIR} + PATHS ${SIMULPACK_LIB_PATH} + PATH_SUFFIXES lib + ) +FIND_LIBRARY(SIMULPACK_SUBDI_COLLAPSE3D NAME subdi_collapse3d + PATHS ${SIMULPACK_DIR} + PATHS ${SIMULPACK_LIB_PATH} + PATH_SUFFIXES lib + ) +FIND_LIBRARY(SIMULPACK_MESH_IO NAME mesh_io + PATHS ${SIMULPACK_DIR} + PATHS ${SIMULPACK_LIB_PATH} + PATH_SUFFIXES lib + ) + +IF (USING_SIMULPACK_TEMPERATURE) +ADD_DEFINITIONS(-DUSING_SIMULPACK_TEMPERATURE) + +FIND_LIBRARY(SIMULPACK_MULTIPHYSICS NAME multiphysics + PATHS ${SIMULPACK_DIR} + PATHS ${SIMULPACK_LIB_PATH} + PATH_SUFFIXES lib + ) +ENDIF (USING_SIMULPACK_TEMPERATURE) + + +set(SIMULPACK_LIBRARIES ${SIMULPACK_MULTIPHYSICS} ${SIMULPACK_MECHANICS} ${SIMULPACK_MESHER3D} ${SIMULPACK_UTILS} ${SIMULPACK_FEM} ${SIMULPACK_MATERIALS} ${SIMULPACK_MYUTILS} ${SIMULPACK_SUBDI_COLLAPSE3D} ${SIMULPACK_PMECHANICS} ${SIMULPACK_MESH_IO}) +SEPARATE_ARGUMENTS(SIMULPACK_LIBRARIES) +#SET(SIMULPACK_INCLUDE_DIR "${SIMULPACK_SRC} ${SIMULPACK_SRC}/utils/include" CACHE STRING "simulpack includes" FORCE) +#SEPARATE_ARGUMENTS(SIMULPACK_INCLUDE_DIR) + +if (NOT SIMULPACK_MECHANICS) + set(SIMULPACK_DIR "" CACHE PATH "Location of SIMULPACK main tree.") + set(SIMULPACK_LIB_PATH "" CACHE PATH "Additional path to search SimulPack libraries" ) +endif(NOT SIMULPACK_MECHANICS) + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SIMULPACK DEFAULT_MSG + SIMULPACK_MECHANICS SIMULPACK_MESHER3D SIMULPACK_UTILS SIMULPACK_FEM SIMULPACK_MATERIALS SIMULPACK_MYUTILS SIMULPACK_SUBDI_COLLAPSE3D SIMULPACK_PMECHANICS SIMULPACK_MESH_IO SIMULPACK_INCLUDE_PATH) + diff --git a/cmake/Modules/FindScotch.cmake b/cmake/Modules/FindScotch.cmake new file mode 100644 index 000000000..88a733c7d --- /dev/null +++ b/cmake/Modules/FindScotch.cmake @@ -0,0 +1,87 @@ +#=============================================================================== +# @file FindScotch.cmake +# +# @author Nicolas Richart +# +# @date creation: Wed Sep 01 2010 +# @date last modification: Tue Sep 09 2014 +# +# @brief The find_package file for Scotch +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +#=============================================================================== +#if(SCOTCH_DIR) +# set(SCOTCH_LIBRARY "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) +#endif(SCOTCH_DIR) + +find_library(SCOTCH_LIBRARY scotch + HINTS ${SCOTCH_DIR} + PATH_SUFFIXES src/libscotch lib + ) + +find_library(SCOTCH_LIBRARY_ERR scotcherr + HINTS ${SCOTCH_DIR} + PATH_SUFFIXES src/libscotch lib + ) + +find_library(SCOTCH_LIBRARY_ERREXIT scotcherrexit + HINTS ${SCOTCH_DIR} + PATH_SUFFIXES src/libscotch lib + ) + +find_library(SCOTCH_LIBRARY_ESMUMPS esmumps + HINTS ${SCOTCH_DIR} + PATH_SUFFIXES src/libscotch lib + ) + +find_path(SCOTCH_INCLUDE_DIR scotch.h + HINTS ${SCOTCH_DIR} + PATH_SUFFIXES include scotch src/libscotch include/scotch + ) + +#=============================================================================== +mark_as_advanced(SCOTCH_LIBRARY) +mark_as_advanced(SCOTCH_LIBRARY_ERR) +mark_as_advanced(SCOTCH_LIBRARY_ERREXIT) +mark_as_advanced(SCOTCH_LIBRARY_ESMUMPS) +mark_as_advanced(SCOTCH_INCLUDE_DIR) + +set(SCOTCH_LIBRARIES_ALL ${SCOTCH_LIBRARY} ${SCOTCH_LIBRARY_ERR}) + +if(SCOTCH_LIBRARY_ESMUMPS) + set(SCOTCH_LIBRARIES_ALL ${SCOTCH_LIBRARY_ESMUMPS} ${SCOTCH_LIBRARIES_ALL}) +endif() + +set(SCOTCH_LIBRARIES ${SCOTCH_LIBRARIES_ALL} CACHE INTERNAL "Libraries for scotch" FORCE) + +#=============================================================================== +if(NOT SCOTCH_FOUND) + set(SCOTCH_DIR "" CACHE PATH "Location of Scotch library.") + mark_as_advanced(SCOTCH_DIR) +endif() + +#=============================================================================== +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Scotch DEFAULT_MSG + SCOTCH_LIBRARY SCOTCH_LIBRARY_ERR SCOTCH_INCLUDE_DIR) + + diff --git a/cmake/Modules/FindSubversion.cmake b/cmake/Modules/FindSubversion.cmake new file mode 100644 index 000000000..39a7ca234 --- /dev/null +++ b/cmake/Modules/FindSubversion.cmake @@ -0,0 +1,89 @@ +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +find_program(Subversion_SVN_EXECUTABLE svn + DOC "subversion command line client") +mark_as_advanced(Subversion_SVN_EXECUTABLE) + +if(Subversion_SVN_EXECUTABLE) + # the subversion commands should be executed with the C locale, otherwise + # the message (which are parsed) may be translated, Alex + set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}") + set(ENV{LC_ALL} C) + + execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} --version + OUTPUT_VARIABLE Subversion_VERSION_SVN + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # restore the previous LC_ALL + set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL}) + + string(REGEX REPLACE "^(.*\n)?svn, version ([.0-9]+).*" + "\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}") + + macro(Subversion_WC_INFO dir prefix) + # the subversion commands should be executed with the C locale, otherwise + # the message (which are parsed) may be translated, Alex + set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}") + set(ENV{LC_ALL} C) + + execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir} + OUTPUT_VARIABLE ${prefix}_WC_INFO + ERROR_VARIABLE Subversion_svn_info_error + RESULT_VARIABLE Subversion_svn_info_result + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(NOT ${Subversion_svn_info_result} EQUAL 0) + set(${prefix}_WC_FOUND FALSE) + if(NOT "${ARGV2}" STREQUAL "ERROR_QUIET") + message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}") + endif(NOT "${ARGV2}" STREQUAL "ERROR_QUIET") + else(NOT ${Subversion_svn_info_result} EQUAL 0) + set(${prefix}_WC_FOUND TRUE) + + string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*" + "\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}") + string(REGEX REPLACE "^(.*\n)?Repository Root: ([^\n]+).*" + "\\2" ${prefix}_WC_ROOT "${${prefix}_WC_INFO}") + string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*" + "\\2" ${prefix}_WC_REVISION "${${prefix}_WC_INFO}") + string(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*" + "\\2" ${prefix}_WC_LAST_CHANGED_AUTHOR "${${prefix}_WC_INFO}") + string(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*" + "\\2" ${prefix}_WC_LAST_CHANGED_REV "${${prefix}_WC_INFO}") + string(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*" + "\\2" ${prefix}_WC_LAST_CHANGED_DATE "${${prefix}_WC_INFO}") + + endif() + + # restore the previous LC_ALL + set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL}) + + endmacro() + + macro(Subversion_WC_LOG dir prefix) + # This macro can block if the certificate is not signed: + # svn ask you to accept the certificate and wait for your answer + # This macro requires a svn server network access (Internet most of the time) + # and can also be slow since it access the svn server + execute_process(COMMAND + ${Subversion_SVN_EXECUTABLE} --non-interactive log -r BASE ${dir} + OUTPUT_VARIABLE ${prefix}_LAST_CHANGED_LOG + ERROR_VARIABLE Subversion_svn_log_error + RESULT_VARIABLE Subversion_svn_log_result + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(NOT ${Subversion_svn_log_result} EQUAL 0) + message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} log -r BASE ${dir}\" failed with output:\n${Subversion_svn_log_error}") + endif() + endmacro() + +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Subversion REQUIRED_VARS Subversion_SVN_EXECUTABLE + VERSION_VAR Subversion_VERSION_SVN ) + +# for compatibility +set(Subversion_FOUND ${SUBVERSION_FOUND}) +set(Subversion_SVN_FOUND ${SUBVERSION_FOUND}) diff --git a/cmake/Modules/PCHgcc.cmake b/cmake/Modules/PCHgcc.cmake new file mode 100644 index 000000000..cc3ccf1e5 --- /dev/null +++ b/cmake/Modules/PCHgcc.cmake @@ -0,0 +1,84 @@ +#=============================================================================== +# @file PCHgcc.cmake +# +# @author Nicolas Richart +# +# @date creation: Wed Aug 31 2011 +# @date last modification: Sun Jan 06 2013 +# +# @brief +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +# (ADD_PCH_RULE _header_filename _src_list) +# Version 7/26/2010 4:55pm +# +# use this macro before "add_executable" +# +# _header_filename +# header to make a .gch +# +# _src_list +# the variable name (do not use ${..}) which contains a +# a list of sources (a.cpp b.cpp c.cpp ...) +# This macro will append a header file to it, then this src_list can be used in +# "add_executable..." +# +# +# Now a .gch file should be generated and gcc should use it. +# (add -Winvalid-pch to the cpp flags to verify) +# +# make clean should delete the pch file +# +# example : ADD_PCH_RULE(headers.h myprog_SRCS) + + +function(ADD_PCH_RULE _header_filename _src_list) + set(_gch_filename "${CMAKE_CURRENT_BINARY_DIR}/${_header_filename}.gch") + + list(APPEND ${_src_list} ${_gch_filename}) + + set(_args ${CMAKE_CXX_FLAGS} -D__aka_inline__=inline) + + get_filename_component(_gch_filename_path ${_gch_filename} PATH) + file(MAKE_DIRECTORY ${_gch_filename_path}) + + # list(APPEND _args -c ${CMAKE_CURRENT_SOURCE_DIR}/${_header_filename}) + list(APPEND _args -c ${CMAKE_CURRENT_SOURCE_DIR}/${_header_filename} -o ${_gch_filename} -Winvalid-pch) + + get_directory_property(DIRINC INCLUDE_DIRECTORIES) + foreach (_inc ${DIRINC}) + list(APPEND _args "-I" ${_inc}) + endforeach(_inc ${DIRINC}) + separate_arguments(_args) + + set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_header_filename} PROPERTIES GENERATED 1) + set_source_files_properties(${_gch_filename} PROPERTIES GENERATED 1) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_header_filename} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${_header_filename} ${CMAKE_CURRENT_BINARY_DIR}/${_header_filename} # ensure same directory! Required by gcc + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_header_filename} + ) + + add_custom_command(OUTPUT ${_gch_filename} + COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} ${_args} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_header_filename} + ) +endfunction(ADD_PCH_RULE _header_filename _src_list) diff --git a/cmake/Modules/ResolveCompilerPaths.cmake b/cmake/Modules/ResolveCompilerPaths.cmake new file mode 100644 index 000000000..644a73864 --- /dev/null +++ b/cmake/Modules/ResolveCompilerPaths.cmake @@ -0,0 +1,105 @@ +# ResolveCompilerPaths - this module defines two macros +# +# RESOLVE_LIBRARIES (XXX_LIBRARIES LINK_LINE) +# This macro is intended to be used by FindXXX.cmake modules. +# It parses a compiler link line and resolves all libraries +# (-lfoo) using the library path contexts (-L/path) in scope. +# The result in XXX_LIBRARIES is the list of fully resolved libs. +# Example: +# +# RESOLVE_LIBRARIES (FOO_LIBRARIES "-L/A -la -L/B -lb -lc -ld") +# +# will be resolved to +# +# FOO_LIBRARIES:STRING="/A/liba.so;/B/libb.so;/A/libc.so;/usr/lib/libd.so" +# +# if the filesystem looks like +# +# /A: liba.so libc.so +# /B: liba.so libb.so +# /usr/lib: liba.so libb.so libc.so libd.so +# +# and /usr/lib is a system directory. +# +# Note: If RESOLVE_LIBRARIES() resolves a link line differently from +# the native linker, there is a bug in this macro (please report it). +# +# RESOLVE_INCLUDES (XXX_INCLUDES INCLUDE_LINE) +# This macro is intended to be used by FindXXX.cmake modules. +# It parses a compile line and resolves all includes +# (-I/path/to/include) to a list of directories. Other flags are ignored. +# Example: +# +# RESOLVE_INCLUDES (FOO_INCLUDES "-I/A -DBAR='\"irrelevant -I/string here\"' -I/B") +# +# will be resolved to +# +# FOO_INCLUDES:STRING="/A;/B" +# +# assuming both directories exist. +# Note: as currently implemented, the -I/string will be picked up mistakenly (cry, cry) +include (CorrectWindowsPaths) + +macro (RESOLVE_LIBRARIES LIBS LINK_LINE) + string (REGEX MATCHALL "((-L|-l|-Wl)([^\" ]+|\"[^\"]+\")|[^\" ]+\\.(a|so|dll|lib))" _all_tokens "${LINK_LINE}") + set (_libs_found) + set (_directory_list) + foreach (token ${_all_tokens}) + if (token MATCHES "-L([^\" ]+|\"[^\"]+\")") + # If it's a library path, add it to the list + string (REGEX REPLACE "^-L" "" token ${token}) + string (REGEX REPLACE "//" "/" token ${token}) + convert_cygwin_path(token) + list (APPEND _directory_list ${token}) + elseif (token MATCHES "^(-l([^\" ]+|\"[^\"]+\")|[^\" ]+\\.(a|so|dll|lib))") + # It's a library, resolve the path by looking in the list and then (by default) in system directories + if (WIN32) #windows expects "libfoo", linux expects "foo" + string (REGEX REPLACE "^-l" "lib" token ${token}) + else (WIN32) + string (REGEX REPLACE "^-l" "" token ${token}) + endif (WIN32) + set (_root) + if (token MATCHES "^/") # We have an absolute path + #separate into a path and a library name: + string (REGEX MATCH "[^/]*\\.(a|so|dll|lib)$" libname ${token}) + string (REGEX MATCH ".*[^${libname}$]" libpath ${token}) + convert_cygwin_path(libpath) + set (_directory_list ${_directory_list} ${libpath}) + set (token ${libname}) + endif (token MATCHES "^/") + set (_lib "NOTFOUND" CACHE FILEPATH "Cleared" FORCE) + find_library (_lib ${token} HINTS ${_directory_list} ${_root}) + if (_lib) + string (REPLACE "//" "/" _lib ${_lib}) + list (APPEND _libs_found ${_lib}) + else (_lib) + message (STATUS "Unable to find library ${token}") + endif (_lib) + endif (token MATCHES "-L([^\" ]+|\"[^\"]+\")") + endforeach (token) + set (_lib "NOTFOUND" CACHE INTERNAL "Scratch variable" FORCE) + # only the LAST occurence of each library is required since there should be no circular dependencies + if (_libs_found) + list (REVERSE _libs_found) + list (REMOVE_DUPLICATES _libs_found) + list (REVERSE _libs_found) + endif (_libs_found) + set (${LIBS} "${_libs_found}") +endmacro (RESOLVE_LIBRARIES) + +macro (RESOLVE_INCLUDES INCS COMPILE_LINE) + string (REGEX MATCHALL "-I([^\" ]+|\"[^\"]+\")" _all_tokens "${COMPILE_LINE}") + set (_incs_found) + foreach (token ${_all_tokens}) + string (REGEX REPLACE "^-I" "" token ${token}) + string (REGEX REPLACE "//" "/" token ${token}) + convert_cygwin_path(token) + if (EXISTS ${token}) + list (APPEND _incs_found ${token}) + else (EXISTS ${token}) + message (STATUS "Include directory ${token} does not exist") + endif (EXISTS ${token}) + endforeach (token) + list (REMOVE_DUPLICATES _incs_found) + set (${INCS} "${_incs_found}") +endmacro (RESOLVE_INCLUDES) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 000000000..2c5184d22 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,51 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Guillaume Anciaux +# @author Nicolas Richart +# +# @date creation: Fri Feb 24 2012 +# @date last modification: Tue Sep 23 2014 +# +# @brief List of examples +# +# @section LICENSE +# +# Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +include_directories( + ${AKANTU_INCLUDE_DIRS} + ${AKANTU_EXTERNAL_LIB_INCLUDE_DIR} + ) + +#=============================================================================== +add_example(new_material "Example on how to add a new material in Akantu" PACKAGE core) +add_example(boundary_conditions "Example on hoy to set boundary conditions" PACKAGE core) +add_example(explicit "Example on how to run an explicit simulation" PACKAGE core) +add_example(implicit "Example on how to run an implicit simulation" PACKAGE implicit) +add_example(static "Example on how to run an explicit simulation" PACKAGE implicit) +add_example(parallel_2d "Example of how to write a parallel code with Akantu" PACKAGE parallel) +add_example(cohesive_element "Cohesive element examples" PACKAGE cohesive_element) +add_example(contact "Examples on how to use contact within Akantu" PACKAGE contact) +add_example(optimization "Optimization examples" PACKAGE optimization) +add_example(structural_mechanics "Structural mechanics model examples" PACKAGE structural_mechanics) +add_example(heat_transfer "Example on how to run heat transfer simulation" PACKAGE heat_transfer) +#=============================================================================== \ No newline at end of file diff --git a/examples/boundary_conditions/CMakeLists.txt b/examples/boundary_conditions/CMakeLists.txt new file mode 100644 index 000000000..aa209f7a6 --- /dev/null +++ b/examples/boundary_conditions/CMakeLists.txt @@ -0,0 +1,39 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Aurelia Isabel Cuba Ramos +# +# @date creation: Fri May 11 2012 +# @date last modification: Thu Nov 01 2012 +# +# @brief boundary condition example configuration +# +# @section LICENSE +# +# Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +add_mesh(plate_mesh square.geo 2 1) + +register_example(plate plate.cc) +add_dependencies(plate plate_mesh) + +file(COPY material.dat DESTINATION .) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/paraview) \ No newline at end of file diff --git a/examples/boundary_conditions/material.dat b/examples/boundary_conditions/material.dat new file mode 100644 index 000000000..e648fe1da --- /dev/null +++ b/examples/boundary_conditions/material.dat @@ -0,0 +1,7 @@ +material elastic [ + name = steel + rho = 7800 # density + E = 2.1e11 # young's modulus + nu = 0.3 # poisson's ratio +] + diff --git a/examples/boundary_conditions/plate.cc b/examples/boundary_conditions/plate.cc new file mode 100644 index 000000000..9211fc1d4 --- /dev/null +++ b/examples/boundary_conditions/plate.cc @@ -0,0 +1,97 @@ +/** + * @file plate.cc + * + * @author Dana Christen + * @author Aurelia Isabel Cuba Ramos + * @author Nicolas Richart + * + * @date creation: Fri May 11 2012 + * @date last modification: Mon Apr 07 2014 + * + * @brief boundary condition example + * + * @section LICENSE + * + * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include "solid_mechanics_model.hh" +/* -------------------------------------------------------------------------- */ +#include +/* -------------------------------------------------------------------------- */ + +using namespace akantu; + +int main(int argc, char *argv[]) { + initialize("material.dat", argc, argv); + + //Do I need to define the element type? + UInt spatial_dimension = 2; + UInt max_steps = 3000; + + Mesh mesh(spatial_dimension); + mesh.read("square.msh"); + mesh.createGroupsFromMeshData("physical_names"); + + SolidMechanicsModel model(mesh); + + /// model initialization + model.initFull(); + + std::cout << model.getMaterial(0) << std::endl; + model.assembleMassLumped(); + + /// Dirichlet boundary conditions + model.applyBC(BC::Dirichlet::FixedValue(0.0, _x), "Fixed_x"); + model.applyBC(BC::Dirichlet::FixedValue(0.0, _y), "Fixed_y"); + + model.updateResidual(); + + model.setBaseName("plate"); + model.addDumpFieldVector("displacement"); + model.addDumpField("blocked_dofs"); + model.addDumpField("force" ); + model.addDumpField("residual" ); + model.dump(); + + Real time_step = model.getStableTimeStep() * .8; + model.setTimeStep(time_step); + + Vector traction(2); + for(UInt s = 1; s <= max_steps; ++s) { + if(s % 100 == 0) + std::cout << "passing step " << s << "/" << max_steps << std::endl; + + // Neumann boundary condition + traction(0) = s*0.1; + traction(1) = 0.0; + model.applyBC(BC::Neumann::FromTraction(traction), "Traction"); + + model.explicitPred(); + model.updateResidual(); + model.updateAcceleration(); + model.explicitCorr(); + + if(s % 10 == 0) + model.dump(); + } + + finalize(); + return EXIT_SUCCESS; +} diff --git a/examples/boundary_conditions/square.geo b/examples/boundary_conditions/square.geo new file mode 100644 index 000000000..3c299d0ec --- /dev/null +++ b/examples/boundary_conditions/square.geo @@ -0,0 +1,29 @@ +// Mesh size +h = 0.005; + +// Dimensions of the square +Lx = 0.01; +Ly = 0.01; + +// ------------------------------------------ +// Geometry +// ------------------------------------------ +Point(1) = { 0.0, 0.0, 0.0, h}; +Point(2) = { Lx, 0.0, 0.0, h}; +Point(3) = { Lx, Ly, 0.0, h}; +Point(4) = { 0.0, Ly, 0.0, h}; + +Line(1) = {1, 2}; +Line(2) = {2, 3}; +Line(3) = {3, 4}; +Line(4) = {4, 1}; + +Line Loop(1) = {1:4}; + +Plane Surface(1) = {1}; + +Physical Surface(1) = {1}; +Physical Line("Fixed_y") = {1}; +Physical Line("Fixed_x") = {4}; +Physical Line("Traction") = {2}; +Physical Line("Free") = {3}; diff --git a/examples/cohesive_element/CMakeLists.txt b/examples/cohesive_element/CMakeLists.txt new file mode 100644 index 000000000..019d7d074 --- /dev/null +++ b/examples/cohesive_element/CMakeLists.txt @@ -0,0 +1,33 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Seyedeh Mohadeseh Taheri Mousavi +# +# @date creation: Fri Jun 21 2013 +# @date last modification: Fri Jun 21 2013 +# +# @brief CMakeLists for the cohesive examples +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +#=============================================================================== + +add_example(cohesive_extrinsic "Extrinsic cohesive element" PACKAGE cohesive_element) +add_example(cohesive_intrinsic "Intrinsic cohesive element" PACKAGE cohesive_element ) +add_example(cohesive_extrinsic_IG_TG "Extrinsic cohesive element with intergranular and transgranular material properties" PACKAGE cohesive_element) \ No newline at end of file diff --git a/examples/cohesive_element/cohesive_extrinsic/CMakeLists.txt b/examples/cohesive_element/cohesive_extrinsic/CMakeLists.txt new file mode 100644 index 000000000..163fd45a9 --- /dev/null +++ b/examples/cohesive_element/cohesive_extrinsic/CMakeLists.txt @@ -0,0 +1,40 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Seyedeh Mohadeseh Taheri Mousavi +# +# @date creation: Fri Jun 21 2013 +# @date last modification: Mon Apr 07 2014 +# +# @brief configuration for extrinsic cohesive elements +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +register_example(cohesive_extrinsic cohesive_extrinsic.cc) +add_mesh(cohesive_extrinsic_mesh triangle.geo 2 2) +add_dependencies(cohesive_extrinsic cohesive_extrinsic_mesh) + +#=============================================================================== + +file(COPY material.dat DESTINATION .) + diff --git a/examples/cohesive_element/cohesive_extrinsic/cohesive_extrinsic.cc b/examples/cohesive_element/cohesive_extrinsic/cohesive_extrinsic.cc new file mode 100644 index 000000000..c7dc095b8 --- /dev/null +++ b/examples/cohesive_element/cohesive_extrinsic/cohesive_extrinsic.cc @@ -0,0 +1,141 @@ +/** + * @file cohesive_extrinsic.cc + * + * @author Seyedeh Mohadeseh Taheri Mousavi + * @author Marco Vocialta + * + * @date creation: Fri Jun 21 2013 + * @date last modification: Thu Jun 05 2014 + * + * @brief Test for cohesive elements + * + * @section LICENSE + * + * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ + +#include +#include +#include + + +/* -------------------------------------------------------------------------- */ +#include "solid_mechanics_model_cohesive.hh" + +/* -------------------------------------------------------------------------- */ + +using namespace akantu; + +int main(int argc, char *argv[]) { + initialize("material.dat", argc, argv); + + const UInt spatial_dimension = 2; + const UInt max_steps = 1000; + + Mesh mesh(spatial_dimension); + mesh.read("triangle.msh"); + + SolidMechanicsModelCohesive model(mesh); + + /// model initialization + model.initFull(SolidMechanicsModelCohesiveOptions(_explicit_lumped_mass, true)); + + Real time_step = model.getStableTimeStep()*0.05; + model.setTimeStep(time_step); + std::cout << "Time step: " << time_step << std::endl; + + CohesiveElementInserter & inserter = model.getElementInserter(); + inserter.setLimit(_y, 0.30, 0.20); + model.updateAutomaticInsertion(); + + Array & position = mesh.getNodes(); + Array & velocity = model.getVelocity(); + Array & boundary = model.getBlockedDOFs(); + Array & displacement = model.getDisplacement(); + + UInt nb_nodes = mesh.getNbNodes(); + + /// boundary conditions + for (UInt n = 0; n < nb_nodes; ++n) { + if (position(n, 1) > 0.99 || position(n, 1) < -0.99) + boundary(n, 1) = true; + + if (position(n, 0) > 0.99 || position(n, 0) < -0.99) + boundary(n, 0) = true; + } + + model.updateResidual(); + + model.setBaseName("extrinsic"); + model.addDumpFieldVector("displacement"); + model.addDumpField("velocity" ); + model.addDumpField("acceleration"); + model.addDumpField("residual" ); + model.addDumpField("stress"); + model.addDumpField("grad_u"); + model.dump(); + + /// initial conditions + Real loading_rate = 0.5; + Real disp_update = loading_rate * time_step; + for (UInt n = 0; n < nb_nodes; ++n) { + velocity(n, 1) = loading_rate * position(n, 1); + } + + /// Main loop + for (UInt s = 1; s <= max_steps; ++s) { + + /// update displacement on extreme nodes + for (UInt n = 0; n < nb_nodes; ++n) { + if (position(n, 1) > 0.99 || position(n, 1) < -0.99) + displacement(n, 1) += disp_update * position(n, 1); + } + + model.checkCohesiveStress(); + + model.explicitPred(); + model.updateResidual(); + model.updateAcceleration(); + model.explicitCorr(); + + if(s % 10 == 0) { + model.dump(); + + std::cout << "passing step " << s << "/" << max_steps << std::endl; + } + } + + Real Ed = model.getEnergy("dissipated"); + + Real Edt = 200*std::sqrt(2); + + std::cout << Ed << " " << Edt << std::endl; + + if (Ed < Edt * 0.999 || Ed > Edt * 1.001 || std::isnan(Ed)) { + std::cout << "The dissipated energy is incorrect" << std::endl; + return EXIT_FAILURE; + } + + + finalize(); + + std::cout << "OK: test_cohesive_extrinsic was passed!" << std::endl; + return EXIT_SUCCESS; +} diff --git a/examples/cohesive_element/cohesive_extrinsic/material.dat b/examples/cohesive_element/cohesive_extrinsic/material.dat new file mode 100644 index 000000000..788956e3d --- /dev/null +++ b/examples/cohesive_element/cohesive_extrinsic/material.dat @@ -0,0 +1,14 @@ +material elastic [ + name = steel + rho = 1e3 # density + E = 1e3 # young's modulus + nu = 0.001 # poisson's ratio +] + +material cohesive_linear [ + name = cohesive + beta = 1 + G_cI = 100 + G_cII = 100 + sigma_c = 100 uniform [0, 0] +] diff --git a/examples/cohesive_element/cohesive_extrinsic/triangle.geo b/examples/cohesive_element/cohesive_extrinsic/triangle.geo new file mode 100644 index 000000000..cbe3dd7a7 --- /dev/null +++ b/examples/cohesive_element/cohesive_extrinsic/triangle.geo @@ -0,0 +1,15 @@ +h = 1.; + +Point(1) = { 1, 1, 0, h}; +Point(2) = {-1, 1, 0, h}; +Point(3) = {-1,-1, 0, h}; +Point(4) = { 1,-1, 0, h}; +Line(1) = {1, 2}; +Line(2) = {2, 3}; +Line(3) = {3, 4}; +Line(4) = {4, 1}; +Line Loop(5) = {1, 2, 3, 4}; +Plane Surface(6) = {5}; +Physical Surface(7) = {6}; + +Transfinite Line {1, 2, 3, 4} = 3; \ No newline at end of file diff --git a/examples/cohesive_element/cohesive_extrinsic_IG_TG/CMakeLists.txt b/examples/cohesive_element/cohesive_extrinsic_IG_TG/CMakeLists.txt new file mode 100644 index 000000000..3028fbb46 --- /dev/null +++ b/examples/cohesive_element/cohesive_extrinsic_IG_TG/CMakeLists.txt @@ -0,0 +1,41 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Seyedeh Mohadeseh Taheri Mousavi +# +# @date creation: Fri Jun 21 2013 +# @date last modification: Fri Jun 21 2013 +# +# @brief Configuration for cohesive_extrinsic_IG_TG +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +register_example(cohesive_extrinsic_IG_TG + cohesive_extrinsic_IG_TG.cc) + + #=============================================================================== +file(COPY material.dat DESTINATION .) +file(COPY square.msh DESTINATION .) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/paraview) + + diff --git a/examples/cohesive_element/cohesive_extrinsic_IG_TG/cohesive_extrinsic_IG_TG.cc b/examples/cohesive_element/cohesive_extrinsic_IG_TG/cohesive_extrinsic_IG_TG.cc new file mode 100644 index 000000000..ded0af86b --- /dev/null +++ b/examples/cohesive_element/cohesive_extrinsic_IG_TG/cohesive_extrinsic_IG_TG.cc @@ -0,0 +1,212 @@ +/** + * @file cohesive_extrinsic_IG_TG.cc + * + * @author Seyedeh Mohadeseh Taheri Mousavi + * @author Marco Vocialta + * + * @date creation: Fri Jun 21 2013 + * @date last modification: Thu Jun 05 2014 + * + * @brief Test for considering different cohesive properties for intergranular (IG) and + * transgranular (TG) fractures in extrinsic cohesive elements + * + * @section LICENSE + * + * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ + +#include +#include +#include + + +/* -------------------------------------------------------------------------- */ +#include "solid_mechanics_model_cohesive.hh" + +/* -------------------------------------------------------------------------- */ + +using namespace akantu; + +class MultiGrainMaterialSelector : public DefaultMaterialCohesiveSelector { +public: + MultiGrainMaterialSelector(const SolidMechanicsModelCohesive & model, const ID & transgranular_id, const ID & intergranular_id) : + DefaultMaterialCohesiveSelector(model), + transgranular_id(transgranular_id), + intergranular_id(intergranular_id), + model(model), + mesh(model.getMesh()), + mesh_facets(model.getMeshFacets()), + spatial_dimension(model.getSpatialDimension()), + nb_IG(0), nb_TG(0) { + } + + UInt operator()(const Element & element) { + if(mesh_facets.getSpatialDimension(element.type) == (spatial_dimension - 1)) { + const std::vector & element_to_subelement = mesh_facets.getElementToSubelement(element.type, element.ghost_type)(element.element); + + const Element & el1 = element_to_subelement[0]; + const Element & el2 = element_to_subelement[1]; + + UInt grain_id1 = mesh.getData("tag_0", el1.type, el1.ghost_type)(el1.element); + if(el2 != ElementNull) { + UInt grain_id2 = mesh.getData("tag_0", el2.type, el2.ghost_type)(el2.element); + if (grain_id1 == grain_id2){ + //transgranular = 0 indicator + nb_TG++; + return model.getMaterialIndex(transgranular_id); + } else { + //intergranular = 1 indicator + nb_IG++; + return model.getMaterialIndex(intergranular_id); + } + } else { + //transgranular = 0 indicator + nb_TG++; + return model.getMaterialIndex(transgranular_id); + } + } else { + return DefaultMaterialCohesiveSelector::operator()(element); + } + } + +private: + ID transgranular_id, intergranular_id; + const SolidMechanicsModelCohesive & model; + const Mesh & mesh; + const Mesh & mesh_facets; + UInt spatial_dimension; + + UInt nb_IG; + UInt nb_TG; +}; + + +/* -------------------------------------------------------------------------- */ +int main(int argc, char *argv[]) { + initialize("material.dat", argc, argv); + + const UInt spatial_dimension = 2; + const UInt max_steps = 1000; + + Mesh mesh(spatial_dimension); + mesh.read("square.msh"); + + SolidMechanicsModelCohesive model(mesh); + + /// model initialization + MultiGrainMaterialSelector material_selector(model, "TG_cohesive", "IG_cohesive"); + model.setMaterialSelector(material_selector); + model.initFull(SolidMechanicsModelCohesiveOptions(_explicit_lumped_mass, true, false)); + + Real time_step = model.getStableTimeStep()*0.05; + model.setTimeStep(time_step); + std::cout << "Time step: " << time_step << std::endl; + + model.assembleMassLumped(); + + Array & position = mesh.getNodes(); + Array & velocity = model.getVelocity(); + Array & boundary = model.getBlockedDOFs(); + Array & displacement = model.getDisplacement(); + + UInt nb_nodes = mesh.getNbNodes(); + + /// boundary conditions + for (UInt n = 0; n < nb_nodes; ++n) { + if (position(n, 1) > 0.99|| position(n, 1) < -0.99) + boundary(n, 1) = true; + + if (position(n, 0) > 0.99 || position(n, 0) < -0.99) + boundary(n, 0) = true; + } + + model.updateResidual(); + + model.setBaseName("extrinsic"); + model.addDumpFieldVector("displacement"); + model.addDumpField("velocity" ); + model.addDumpField("acceleration"); + model.addDumpField("residual" ); + model.addDumpField("stress"); + model.addDumpField("grad_u"); + model.dump(); + + /// initial conditions + Real loading_rate = 0.1; + // bar_height = 2 + Real VI = loading_rate * 2* 0.5; + for (UInt n = 0; n < nb_nodes; ++n) { + velocity(n, 1) = loading_rate * position(n, 1); + velocity(n, 0) = loading_rate * position(n, 0); + } + + model.dump(); + + Real dispy = 0; + + /// Main loop + for (UInt s = 1; s <= max_steps; ++s) { + dispy += VI * time_step; + /// update displacement on extreme nodes + for (UInt n = 0; n < mesh.getNbNodes(); ++n) { + if (position(n, 1) > 0.99){ + displacement(n, 1) = dispy; + velocity(n,1) = VI;} + if (position(n, 1) < -0.99){ + displacement(n, 1) = -dispy; + velocity(n,1) = -VI;} + if (position(n, 0) > 0.99){ + displacement(n, 0) = dispy; + velocity(n,0) = VI;} + if (position(n, 0) < -0.99){ + displacement(n, 0) = -dispy; + velocity(n,0) = -VI;} + } + + model.checkCohesiveStress(); + + model.explicitPred(); + model.updateResidual(); + model.updateAcceleration(); + model.explicitCorr(); + + model.dump(); + if(s % 10 == 0) { + std::cout << "passing step " << s << "/" << max_steps << std::endl; + } + } + + Real Ed = model.getEnergy("dissipated"); + + Real Edt = 40; + + std::cout << Ed << " " << Edt << std::endl; + + if (Ed < Edt * 0.999 || Ed > Edt * 1.001 || std::isnan(Ed)) { + std::cout << "The dissipated energy is incorrect" << std::endl; + finalize(); + return EXIT_FAILURE; + } + + finalize(); + + std::cout << "OK: test_cohesive_extrinsic_IG_TG was passed!" << std::endl; + return EXIT_SUCCESS; +} diff --git a/examples/cohesive_element/cohesive_extrinsic_IG_TG/material.dat b/examples/cohesive_element/cohesive_extrinsic_IG_TG/material.dat new file mode 100644 index 000000000..04e600686 --- /dev/null +++ b/examples/cohesive_element/cohesive_extrinsic_IG_TG/material.dat @@ -0,0 +1,20 @@ +material elastic [ + name = steel + rho = 1e3 # density + E = 1e3 # young's modulus + nu = 0.0 # poisson's ratio +] + +material cohesive_linear [ + name = TG_cohesive + beta = 0 + G_cI = 10 + sigma_c = 100 +] + +material cohesive_linear [ + name = IG_cohesive + beta = 0 + G_cI = 10 + sigma_c = 20 +] diff --git a/examples/cohesive_element/cohesive_extrinsic_IG_TG/square.msh b/examples/cohesive_element/cohesive_extrinsic_IG_TG/square.msh new file mode 100644 index 000000000..e34221c8e --- /dev/null +++ b/examples/cohesive_element/cohesive_extrinsic_IG_TG/square.msh @@ -0,0 +1,66 @@ +$MeshFormat +2.2 0 8 +$EndMeshFormat +$Nodes +41 +1 1 1 0 +2 -1 1 0 +3 -1 -1 0 +4 1 -1 0 +5 2.081668171172169e-12 1 0 +6 0.5000000000009475 1 0 +7 -0.4999999999989593 1 0 +8 -1 2.081668171172169e-12 0 +9 -1 0.5000000000009475 0 +10 -1 -0.4999999999989593 0 +11 -2.081668171172169e-12 -1 0 +12 -0.5000000000009475 -1 0 +13 0.4999999999989593 -1 0 +14 1 -2.081668171172169e-12 0 +15 1 -0.5000000000009475 0 +16 1 0.4999999999989593 0 +17 -2.888892828660043e-14 2.890280607440824e-14 0 +18 0.4999999999993061 -0.500000000000694 0 +19 0.500000000000694 0.4999999999993061 0 +20 -0.4999999999993061 0.500000000000694 0 +21 -0.5000000000006987 -0.4999999999993013 0 +22 0.7499999999996531 -0.7500000000003471 0 +23 0.2499999999986122 -0.7500000000003471 0 +24 0.7500000000003471 0.7499999999996531 0 +25 0.7500000000003471 0.2499999999986122 0 +26 -0.7499999999996531 0.7500000000003471 0 +27 -0.2499999999986122 0.7500000000003471 0 +28 -0.7500000000003493 -0.7499999999996506 0 +29 -0.7500000000003493 -0.2499999999986098 0 +30 1.026389621442784e-12 0.5000000000000144 0 +31 0.2500000000003326 0.2499999999996675 0 +32 0.2500000000013878 0.7499999999996531 0 +33 0.4999999999999856 -1.02638268254888e-12 0 +34 0.2499999999996386 -0.2500000000003325 0 +35 0.7499999999996531 -0.2500000000013878 0 +36 -0.2499999999996675 0.2500000000003614 0 +37 -0.5000000000000144 1.055285488623288e-12 0 +38 -0.7499999999996531 0.2500000000013878 0 +39 -1.055278549729385e-12 -0.4999999999999855 0 +40 -0.2500000000003638 -0.2499999999996362 0 +41 -0.2500000000013902 -0.7499999999996507 0 +$EndNodes +$Elements +16 +1 9 2 1 1 4 18 11 22 23 13 +2 9 2 2 2 1 19 14 24 25 16 +3 9 2 2 2 2 20 5 26 27 7 +4 9 2 1 1 3 21 8 28 29 10 +5 9 2 2 2 5 17 19 30 31 32 +6 9 2 1 1 14 17 18 33 34 35 +7 9 2 2 2 14 19 17 25 31 33 +8 9 2 2 2 5 20 17 27 36 30 +9 9 2 2 2 8 17 20 37 36 38 +10 9 2 1 1 11 18 17 23 34 39 +11 9 2 1 1 8 21 17 29 40 37 +12 9 2 1 1 11 17 21 39 40 41 +13 9 2 1 1 4 14 18 15 35 22 +14 9 2 2 2 2 8 20 9 38 26 +15 9 2 1 1 3 11 21 12 41 28 +16 9 2 2 2 1 5 19 6 32 24 +$EndElements diff --git a/examples/cohesive_element/cohesive_intrinsic/CMakeLists.txt b/examples/cohesive_element/cohesive_intrinsic/CMakeLists.txt new file mode 100644 index 000000000..312c8707b --- /dev/null +++ b/examples/cohesive_element/cohesive_intrinsic/CMakeLists.txt @@ -0,0 +1,45 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Seyedeh Mohadeseh Taheri Mousavi +# +# @date creation: Fri Jun 21 2013 +# @date last modification: Fri Jun 21 2013 +# +# @brief Intrinsic cohesive element configuration +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +add_mesh( cohesive_intrinsic_mesh triangle.geo 2 2) + + +register_example(cohesive_intrinsic + cohesive_intrinsic.cc) + +add_dependencies(cohesive_intrinsic + cohesive_intrinsic_mesh) + + + #=============================================================================== +file(COPY material.dat DESTINATION .) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/paraview) diff --git a/examples/cohesive_element/cohesive_intrinsic/cohesive_intrinsic.cc b/examples/cohesive_element/cohesive_intrinsic/cohesive_intrinsic.cc new file mode 100644 index 000000000..6d8916bd0 --- /dev/null +++ b/examples/cohesive_element/cohesive_intrinsic/cohesive_intrinsic.cc @@ -0,0 +1,174 @@ +/** + * @file cohesive_intrinsic.cc + * + * @author Seyedeh Mohadeseh Taheri Mousavi + * @author Marco Vocialta + * + * @date creation: Fri Jun 21 2013 + * @date last modification: Thu Jun 05 2014 + * + * @brief Test for cohesive elements + * + * @section LICENSE + * + * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include +#include +#include + +/* -------------------------------------------------------------------------- */ +#include "aka_common.hh" +#include "mesh.hh" +#include "mesh_io.hh" +#include "mesh_io_msh.hh" +#include "mesh_utils.hh" +#include "solid_mechanics_model_cohesive.hh" +#include "material.hh" +//#include "io_helper.hh" +/* -------------------------------------------------------------------------- */ + +using namespace akantu; + +static void updateDisplacement(SolidMechanicsModelCohesive &, + Array &, + ElementType, + Real); + +int main(int argc, char *argv[]) { + initialize("material.dat", argc, argv); + + // debug::setDebugLevel(dblDump); + + const UInt spatial_dimension = 2; + const UInt max_steps = 350; + + const ElementType type = _triangle_6; + + Mesh mesh(spatial_dimension); + mesh.read("triangle.msh"); + + CohesiveElementInserter inserter(mesh); + inserter.setLimit(_x, -0.26, -0.24); + inserter.insertIntrinsicElements(); + + SolidMechanicsModelCohesive model(mesh); + + /// model initialization + model.initFull(); + + Real time_step = model.getStableTimeStep()*0.8; + model.setTimeStep(time_step); + std::cout << "Time step: " << time_step << std::endl; + + Array & boundary = model.getBlockedDOFs(); + + UInt nb_nodes = mesh.getNbNodes(); + UInt nb_element = mesh.getNbElement(type); + + /// boundary conditions + for (UInt dim = 0; dim < spatial_dimension; ++dim) { + for (UInt n = 0; n < nb_nodes; ++n) { + boundary(n, dim) = true; + } + } + + model.updateResidual(); + + model.setBaseName("intrinsic"); + model.addDumpFieldVector("displacement"); + model.addDumpField("velocity" ); + model.addDumpField("acceleration"); + model.addDumpField("residual" ); + model.addDumpField("stress"); + model.addDumpField("grad_u"); + model.addDumpField("force"); + model.dump(); + + + /// update displacement + Array elements; + Real * bary = new Real[spatial_dimension]; + for (UInt el = 0; el < nb_element; ++el) { + mesh.getBarycenter(el, type, bary); + if (bary[0] > -0.25) elements.push_back(el); + } + delete[] bary; + + Real increment = 0.01; + + updateDisplacement(model, elements, type, increment); + + /// Main loop + for (UInt s = 1; s <= max_steps; ++s) { + model.solveStep(); + + updateDisplacement(model, elements, type, increment); + + if(s % 1 == 0) { + model.dump(); + std::cout << "passing step " << s << "/" << max_steps << std::endl; + } + } + + Real Ed = model.getEnergy("dissipated"); + + Real Edt = 2 * sqrt(2); + + std::cout << Ed << " " << Edt << std::endl; + + if (Ed < Edt * 0.999 || Ed > Edt * 1.001 || std::isnan(Ed)) { + std::cout << "The dissipated energy is incorrect" << std::endl; + return EXIT_FAILURE; + } + + finalize(); + + std::cout << "OK: test_cohesive_intrinsic was passed!" << std::endl; + return EXIT_SUCCESS; +} + + +static void updateDisplacement(SolidMechanicsModelCohesive & model, + Array & elements, + ElementType type, + Real increment) { + + Mesh & mesh = model.getMesh(); + UInt nb_element = elements.getSize(); + UInt nb_nodes = mesh.getNbNodes(); + UInt nb_nodes_per_element = mesh.getNbNodesPerElement(type); + + const Array & connectivity = mesh.getConnectivity(type); + Array & displacement = model.getDisplacement(); + Array update(nb_nodes); + update.clear(); + + for (UInt el = 0; el < nb_element; ++el) { + for (UInt n = 0; n < nb_nodes_per_element; ++n) { + UInt node = connectivity(elements(el), n); + if (!update(node)) { + displacement(node, 0) -= increment; + // displacement(node, 1) += increment; + update(node) = true; + } + } + } +} diff --git a/examples/cohesive_element/cohesive_intrinsic/material.dat b/examples/cohesive_element/cohesive_intrinsic/material.dat new file mode 100644 index 000000000..7af5e3059 --- /dev/null +++ b/examples/cohesive_element/cohesive_intrinsic/material.dat @@ -0,0 +1,16 @@ +material elastic [ + name = steel + rho = 1 # density + E = 1 # young's modulus + nu = 0.1 # poisson's ratio +] + +material cohesive_bilinear [ + name = cohesive + sigma_c = 1 + beta = 1.5 + G_cI = 1 + G_cII = 1 + delta_0 = 0.1 + penalty = 1e10 +] diff --git a/examples/cohesive_element/cohesive_intrinsic/triangle.geo b/examples/cohesive_element/cohesive_intrinsic/triangle.geo new file mode 100644 index 000000000..cbe3dd7a7 --- /dev/null +++ b/examples/cohesive_element/cohesive_intrinsic/triangle.geo @@ -0,0 +1,15 @@ +h = 1.; + +Point(1) = { 1, 1, 0, h}; +Point(2) = {-1, 1, 0, h}; +Point(3) = {-1,-1, 0, h}; +Point(4) = { 1,-1, 0, h}; +Line(1) = {1, 2}; +Line(2) = {2, 3}; +Line(3) = {3, 4}; +Line(4) = {4, 1}; +Line Loop(5) = {1, 2, 3, 4}; +Plane Surface(6) = {5}; +Physical Surface(7) = {6}; + +Transfinite Line {1, 2, 3, 4} = 3; \ No newline at end of file diff --git a/examples/contact/CMakeLists.txt b/examples/contact/CMakeLists.txt new file mode 100644 index 000000000..67168b8ad --- /dev/null +++ b/examples/contact/CMakeLists.txt @@ -0,0 +1,57 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Alejandro M. Aragón +# +# @date Mon Mar 24 11:30:00 2014 +# +# @brief configuration file for contact examples +# +# @section LICENSE +# +# Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +register_example(hertz_2D hertz_2D.cc) + +add_mesh(hertz_2D_mesh hertz_2D.geo 2 1) +add_dependencies(hertz_2D hertz_2D_mesh) + + +register_example(hertz_3D hertz_3D.cc) + +add_mesh(hertz_3D_mesh hertz_3D.geo 3 1) +add_dependencies(hertz_3D hertz_3D_mesh) + + +register_example(tetrahedra tetrahedra.cc) + +add_mesh(tetrahedra_mesh tetrahedra.geo 3 1) +add_dependencies(tetrahedra tetrahedra_mesh) + + +register_example(blocks blocks.cc) + +add_mesh(blocks_mesh blocks.geo 2 1) +add_dependencies(blocks blocks_mesh) + + +#=============================================================================== +file(COPY steel.dat DESTINATION .) \ No newline at end of file diff --git a/examples/contact/blocks.cc b/examples/contact/blocks.cc new file mode 100644 index 000000000..33776efc4 --- /dev/null +++ b/examples/contact/blocks.cc @@ -0,0 +1,136 @@ +/** + * @file blocks.cc + * + * @author Alejandro M. Aragón + * + * @date Tue Jan 14 09:38:00 2014 + * + * @brief Example of two blocks in contact + * + * @section LICENSE + * + * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + + +#include +#include + +#include "contact_impl.hh" + +using namespace akantu; + + +using std::cout; +using std::endl; + +int main(int argc, char *argv[]) { + + // set dimension + static const UInt dim = 2; + + typedef std::chrono::high_resolution_clock clock; + typedef std::chrono::seconds seconds; + + typedef SolidMechanicsModel model_type; + + typedef Contact > + contact_type; + + // capture initial time + clock::time_point t0 = clock::now(); + + initialize("steel.dat", argc, argv); + + // create and read mesh + Mesh mesh(dim); + mesh.read("blocks.msh"); + + // create model + model_type model(mesh); + SolidMechanicsModelOptions opt(_static); + + // initialize material + model.initFull(opt); + + // setup paraview dumper + model.setBaseName("contact"); + model.addDumpFieldVector("displacement"); + + // create data structure that holds contact data + contact_type cd(argc, argv, model); + + // get areas for slave nodes + mesh.createGroupsFromMeshData("physical_names"); + model.applyBC(BC::Neumann::FromHigherDim(Matrix::eye(2,1.)), "interface_top"); + Array& areas = model.getForce(); + + ElementGroup &eg = mesh.getElementGroup("interface_top"); + for (auto nit = eg.node_begin(); nit != eg.node_end(); ++nit) { + + // add slave node + cd.addSlave(*nit); + + // compute and add area + Real a = 0.; + for (UInt i=0; i(cd); + } + + clock::time_point t1 = clock::now(); + + seconds total_s = std::chrono::duration_cast(t1 - t0); + + cout<<"- Simulation took "< + * + * @date Tue Jan 14 09:38:00 2014 + * + * @brief File used to obtain 2D implicit contact results and compare with + * Hertz theory + * + * @section LICENSE + * + * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +#include + +#include "contact_impl.hh" + +using namespace akantu; + +using std::cout; +using std::endl; +using std::setw; +using std::setprecision; + +int main(int argc, char *argv[]) { + // set dimension + static const UInt dim = 2; + + typedef Point point_type; + typedef BoundingBox bbox_type; + typedef SolidMechanicsModel model_type; + typedef Contact > + contact_type; + + typedef std::chrono::high_resolution_clock clock; + typedef std::chrono::seconds seconds; + + clock::time_point t0 = clock::now(); + + initialize("steel.dat", argc, argv); + + // create mesh + Mesh mesh(dim); + + // read mesh + mesh.read("hertz_2D.msh"); + + // create model + model_type model(mesh); + SolidMechanicsModelOptions opt(_static); + + // initialize material + model.initFull(opt); + model.updateCurrentPosition(); + + // create data structure that holds contact data + contact_type cd(argc, argv, model); + + // optimal value of penalty multiplier + cd[Alpha] = 1.e-6; + cd[Verbose] = true; + + // set Paraview output resluts + model.setBaseName("contact"); + model.addDumpFieldVector("displacement"); + + // use bounding box to minimize slave-master pairs + Real r0 = 0.5; + Real r1 = 0.15; + point_type c1(-r0 / 2, -r1 / 2); + point_type c2(r0 / 2, r1 / 2); + bbox_type bb(c1, c2); + + // get physical names from mesh + Array &coords = mesh.getNodes(); + mesh.createGroupsFromMeshData ("physical_names"); + + // compute areas for slave nodes that are used for the computation of contact pressures + model.applyBC(BC::Neumann::FromHigherDim(Matrix ::eye(2, 1.)), "contact_surface"); + // NOTE: the areas are computed by assigning a unit pressure to the contact surface, + // then the magnitude of the resulting force vector at nodes gives its associated area + Array & areas = model.getForce(); + + // add slave-master pairs and store slave node areas + ElementGroup &eg = mesh.getElementGroup("contact_surface"); + for (auto nit = eg.node_begin(); nit != eg.node_end(); ++nit) { + // get point of slave node + point_type n(&coords(*nit)); + + // process only if within bounding box + if (bb & n) { + cd.addSlave(*nit); + + // compute and add area to slave node + Real a = 0.; + for (UInt i = 0; i < dim; ++i) + a += pow(areas(*nit, i), 2.); + cd.addArea(*nit, sqrt(a)); + } + } + + // clear force vector before the start of the simulation + areas.clear(); + + // add master surface to find pairs + cd.searchSurface("rigid"); + + // output contact data info + cout << cd; + + // apply boundary conditions + model.applyBC(BC::Dirichlet::FixedValue(0., _x), "rigid"); + model.applyBC(BC::Dirichlet::FixedValue(0., _y), "rigid"); + model.getBlockedDOFs()(7, 0) = true; + + Real data[3][50]; // store results for printing + Real step = 0.001; // top displacement increment + Real Delta = 0.05; // maximum imposed displacement + size_t k = 0; + + // loop over displacement increments + for (Real delta = step; delta <= Delta + step; delta += step) { + // apply displacement at the top + model.applyBC(BC::Dirichlet::FixedValue(-delta, _y), "top"); + + // solve contact step (no need to call solve on the model object) + solveContactStep<_generalized_newton>(cd); + + data[0][k] = delta; + data[1][k] = cd.getForce(); + data[2][k] = cd.getMaxPressure(); + ++k; + } + + // print results + size_t w = 10; + cout << setprecision(2); + cout << "\n\n" << setw(w) << "Disp." << setw(w) << "Force" << setw(w) << "Max pressure" << endl; + for (int i = 0; i < 50; ++i) + cout << setw(w) << data[0][i] << setw(w) << data[1][i] << setw(w) << data[2][i] << endl; + + clock::time_point t1 = clock::now(); + seconds total_s = std::chrono::duration_cast (t1 - t0); + cout << "*** INFO *** Simulation took " << total_s.count() << " s" << endl; + + // finalize simulation + finalize(); + return EXIT_SUCCESS; +} diff --git a/examples/contact/hertz_2D.geo b/examples/contact/hertz_2D.geo new file mode 100644 index 000000000..5dfc70800 --- /dev/null +++ b/examples/contact/hertz_2D.geo @@ -0,0 +1,29 @@ +cl1 = 0.01; +cl2 = 0.1; +cl3 = 1; +Dy = 0.1; +Point(1) = {0, 0.1-Dy, 0, cl1}; +Point(2) = {0.5, 0.6-Dy, 0, cl2}; +Point(3) = {-0.5, 0.6-Dy, 0, cl2}; +Point(4) = {0.5, 0, 0, cl3}; +Point(5) = {-0.5, 0, 0, cl3}; +Point(6) = {-0.5, -0.25, 0, cl3}; +Point(7) = {0.5, -0.25, 0, cl3}; +Point(8) = {0, 0.6-Dy, 0, cl2}; +Circle(1) = {3, 8, 1}; +Circle(2) = {1, 8, 2}; +Line(3) = {2, 8}; +Line(13) = {8, 3}; +Line(4) = {6, 7}; +Line(5) = {7, 4}; +Line(6) = {4, 5}; +Line(7) = {5, 6}; +Line Loop(9) = {2, 3, 13, 1}; +Plane Surface(9) = {9}; +Line Loop(11) = {6, 7, 4, 5}; +Plane Surface(11) = {11}; +Physical Line("rigid") = {6}; +Physical Line("contact_surface") = {1, 2}; +Physical Line("top") = {3, 13}; +Physical Surface("top_body") = {9}; +Physical Surface("bottom_body") = {11}; diff --git a/examples/contact/hertz_3D.cc b/examples/contact/hertz_3D.cc new file mode 100644 index 000000000..9e0ff5c9c --- /dev/null +++ b/examples/contact/hertz_3D.cc @@ -0,0 +1,185 @@ +/** + * @file hertz_3D.cc + * + * @author Alejandro M. Aragón + * + * @date Fri Apr 4 11:30:00 2014 + * + * @brief File used to obtain 3D implicit contact results and compare with + * Hertz theory + * + * @section LICENSE + * + * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +#include + +#include "contact_impl.hh" + +using namespace akantu; + +using std::cout; +using std::endl; +using std::setw; +using std::setprecision; + +int main(int argc, char *argv[]) { + + // set dimension + static const UInt dim = 3; + + // type definitions + typedef Point point_type; + typedef BoundingBox bbox_type; + typedef SolidMechanicsModel model_type; + typedef Contact > + contact_type; + + typedef std::chrono::high_resolution_clock clock; + typedef std::chrono::seconds seconds; + + clock::time_point t0 = clock::now(); + + initialize("steel.dat", argc, argv); + + // create mesh + Mesh mesh(dim); + + // read mesh + mesh.read("hertz_3D.msh"); + + // create model + model_type model(mesh); + SolidMechanicsModelOptions opt(_static); + + // initialize material + model.initFull(opt); + + // create data structure that holds contact data + contact_type cd(argc, argv, model); + + // optimal value of penalty multiplier + cd[Alpha] = 0.05; + cd[Multiplier_tol] = 1.e-2; + cd[Newton_tol] = 1.e-2; + cd[Verbose] = true; + + // set Paraview output resluts + model.setBaseName("contact"); + model.addDumpFieldVector("displacement"); + + // call update current position to be able to call later + // the function to get current positions + model.updateCurrentPosition(); + + // get physical names from Gmsh file + mesh.createGroupsFromMeshData("physical_names"); + + // set-up bounding box to include slave nodes that lie inside it + Real l1 = 1.; + Real l2 = 0.2; + Real l3 = 1.; + point_type c1(-l1 / 2, -l2 / 2, -l3 / 2); + point_type c2(l1 / 2, l2 / 2, l3 / 2); + bbox_type bb(c1, c2); + + // get areas for the nodes of the circle + // this is done by applying a unit pressure to the contact surface elements + model.applyBC(BC::Neumann::FromHigherDim(Matrix::eye(3, 1.)), + "contact_surface"); + Array &areas = model.getForce(); + + // loop over contact surface nodes and store node areas + ElementGroup &eg = mesh.getElementGroup("contact_surface"); + Array &coords = mesh.getNodes(); + + cout << "- Adding areas to slave nodes. " << endl; + for (auto nit = eg.node_begin(); nit != eg.node_end(); ++nit) { + + point_type p(&coords(*nit)); + + // ignore slave node if it doesn't lie within the bounding box + if (!(bb & p)) + continue; + + cd.addSlave(*nit); + + // compute area contributing to the slave node + Real a = 0.; + for (UInt i = 0; i < dim; ++i) + a += pow(areas(*nit, i), 2.); + cd.addArea(*nit, sqrt(a)); + } + + // set force value to zero + areas.clear(); + + // add master surface to find pairs + cd.searchSurface("rigid_surface"); + + // apply boundary conditions for the rigid plane + model.applyBC(BC::Dirichlet::FixedValue(0., _x), "bottom_body"); + model.applyBC(BC::Dirichlet::FixedValue(0., _y), "bottom_body"); + model.applyBC(BC::Dirichlet::FixedValue(0., _z), "bottom_body"); + + // block z-disp in extreme points of top surface + model.getBlockedDOFs()(1, 2) = true; + model.getBlockedDOFs()(2, 2) = true; + + // block x-disp in extreme points of top surface + model.getBlockedDOFs()(3, 0) = true; + model.getBlockedDOFs()(4, 0) = true; + + const size_t steps = 30; + Real data[3][steps]; // store results for printing + Real step = 0.001; // top displacement increment + size_t k = 0; + + for (Real delta = 0; delta <= step * steps; delta += step) { + // apply displacement to the top surface of the half-sphere + model.applyBC(BC::Dirichlet::FixedValue(-delta, _y), "top_surface"); + + // solve contact step, this function also dumps Paraview files + solveContactStep<_uzawa>(cd); + // solveContactStep<_generalized_newton>(cd); + + data[0][k] = delta; + data[1][k] = cd.getForce(); + data[2][k] = cd.getMaxPressure(); + ++k; + } + + // print results + size_t w = 14; + cout << setprecision(4); + cout << endl << setw(w) << "Disp." << setw(w) << "Force" << setw(w) + << "Max pressure" << endl; + for (size_t i = 0; i < steps; ++i) + cout << setw(w) << data[0][i] << setw(w) << data[1][i] << setw(w) + << data[2][i] << endl; + + clock::time_point t1 = clock::now(); + seconds total_s = std::chrono::duration_cast(t1 - t0); + cout << "*** INFO *** Simulation took " << total_s.count() << " s" << endl; + + // finalize simulation + finalize(); + return EXIT_SUCCESS; +} diff --git a/examples/contact/hertz_3D.geo b/examples/contact/hertz_3D.geo new file mode 100644 index 000000000..c9a78db78 --- /dev/null +++ b/examples/contact/hertz_3D.geo @@ -0,0 +1,54 @@ +cl1 = 0.005; +cl2 = 0.1; +cl3 = 0.4; +Dy = 0.099; +Dz = 1; +Point(1) = {0, 0.1-Dy, 0, cl1}; +Point(2) = {0.5, 0.6-Dy, 0, cl2}; +Point(3) = {-0.5, 0.6-Dy, 0, cl2}; +Point(4) = {0, 0.6-Dy, 0, cl2}; +Point(5) = {0, 0.6-Dy, -0.5, cl2}; +Point(6) = {0, 0.6-Dy, 0.5, cl2}; + +Point(7) = {0, 0, 0, cl3}; +Point(8) = {0.5, 0, 0, cl3}; +Point(9) = {-0.5, 0, 0, cl3}; +Point(10) = {0, 0, -0.5, cl3}; +Point(11) = {0, 0, 0.5, cl3}; + +Circle(1) = {3, 4, 1}; +Circle(2) = {1, 4, 2}; +Circle(3) = {6, 4, 1}; +Circle(4) = {1, 4, 5}; +Circle(5) = {3, 4, 6}; +Circle(6) = {6, 4, 2}; +Circle(7) = {2, 4, 5}; +Circle(8) = {5, 4, 3}; +Line Loop(1) = {3, 2, -6}; +Ruled Surface(1) = {1}; +Line Loop(2) = {-2, -7, 4}; +Ruled Surface(2) = {2}; +Line Loop(3) = {-4, -8, -1}; +Ruled Surface(3) = {3}; +Line Loop(4) = {1, -3, -5}; +Ruled Surface(4) = {4}; +Line Loop(5) = {6, 7, 8, 5}; +Plane Surface(5) = {5}; +Surface Loop(1) = {3, 2, 1, 4, 5}; +Volume(1) = {1}; + +Circle(9) = {9, 7, 11}; +Circle(10) = {11, 7, 8}; +Circle(11) = {8, 7, 10}; +Circle(12) = {10, 7, 9}; +Line Loop(6) = {10, 11, 12, 9}; +Plane Surface(6) = {6}; +Extrude {0, -cl3, 0} { + Surface{6}; +} + +Physical Surface("top_surface") = {5}; +Physical Surface("rigid_surface") = {6}; +Physical Volume("top_body") = {1}; +Physical Volume("bottom_body") = {2}; +Physical Surface("contact_surface") = {1, 2, 4, 3}; diff --git a/examples/contact/steel.dat b/examples/contact/steel.dat new file mode 100644 index 000000000..fae183ada --- /dev/null +++ b/examples/contact/steel.dat @@ -0,0 +1,7 @@ +material neohookean [ + name = steel + rho = 7500 # kg/m^3 + E = 2e11 # GPa + nu = 0. + finite_deformation = 1 +] diff --git a/examples/contact/tetrahedra.cc b/examples/contact/tetrahedra.cc new file mode 100644 index 000000000..54dc49336 --- /dev/null +++ b/examples/contact/tetrahedra.cc @@ -0,0 +1,109 @@ +/** + * @file tetrahedra.cc + * + * @author Alejandro M. Aragón + * + * @date Tue Jan 14 09:38:00 2014 + * + * @brief File used to obtain contact results for a simple tetrahedra test + * + * @section LICENSE + * + * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +#include "contact_impl.hh" + +//#include "implicit_contact_manager.hh" + +using namespace akantu; + +int main(int argc, char *argv[]) { + + // set dimension + static const UInt dim = 3; + + typedef SolidMechanicsModel model_type; +// typedef ContactData contact_type; + typedef Contact > + contact_type; + + + // initialize akantu + initialize("steel.dat", argc, argv); + + // create and read mesh + Mesh mesh(dim); + mesh.read("tetrahedra.msh"); + + // create model + model_type model(mesh); + SolidMechanicsModelOptions opt(_static); + + // initialize model + model.initFull(opt); + + // paraview output + model.setBaseName("contact"); + model.addDumpFieldVector("displacement"); + + // create conctact object + contact_type cd(argc, argv, model); + + // add slave node of the tip of the top tetrahedron + cd.addSlave(4); + + // parameters + cd[Verbose] = true; + + // add search surface + cd.searchSurface("master"); + + // apply boundary conditions + mesh.createGroupsFromMeshData("physical_names"); + + using BC::Dirichlet::FixedValue; +// model.applyBC(FixedValue(0., _y), "top_surface"); + model.applyBC(FixedValue(0., _x), "top_surface"); + model.applyBC(FixedValue(0., _z), "top_surface"); + model.applyBC(FixedValue(0., _x), "bottom_surface"); + model.applyBC(FixedValue(0., _y), "bottom_surface"); + model.applyBC(FixedValue(0., _z), "bottom_surface"); + +// model.applyBC(FixedValue(0., _x), "master"); +// model.applyBC(FixedValue(0., _y), "master"); +// model.applyBC(FixedValue(0., _z), "master"); + + Real U = 2; + Real Du = 0.01; + + for (Real u = Du; u<=U; u += Du) { + +// model.applyBC(FixedValue(u, _x), "top_surface"); + model.applyBC(FixedValue(-u, _y), "top_surface"); + + // solve contact step (no need to call solve on the model object) +// solveContactStep<_uzawa>(cd); + solveContactStep<_generalized_newton>(cd); + } + + + // finalize simulation + finalize(); + return EXIT_SUCCESS; +} diff --git a/examples/contact/tetrahedra.geo b/examples/contact/tetrahedra.geo new file mode 100644 index 000000000..13859bf02 --- /dev/null +++ b/examples/contact/tetrahedra.geo @@ -0,0 +1,69 @@ +cl1 = 4; +off = 0.; +Point(1) = {-0.5, -0.5, -0.5, cl1}; +Point(2) = {-0.5, 0.5, -0.5, cl1}; +Point(3) = {0.5, 0.5, -0.5, cl1}; +Point(4) = {0.5, -0.5, -0.5, cl1}; +Point(5) = {0.25, 1.2, 0 + off, cl1}; +Point(6) = {0.75, 1.9, -0.5 + off, cl1}; +Point(7) = {-0.25, 1.9, -0.5 + off, cl1}; +Point(11) = {-0.5, -0.5, 0.5, cl1}; +Point(12) = {-0.5, 0.5, 0.5, cl1}; +Point(13) = {0.5, 0.5, 0.5, cl1}; +Point(14) = {0.5, -0.5, 0.5, cl1}; +Point(26) = {0.75, 1.9, 0.5 + off, cl1}; +Point(27) = {-0.25, 1.9, 0.5 + off, cl1}; +Line(1) = {1, 4}; +Line(2) = {4, 3}; +Line(3) = {3, 2}; +Line(4) = {2, 1}; +Line(5) = {5, 6}; +Line(6) = {6, 7}; +Line(7) = {7, 5}; +Line(11) = {11, 14}; +Line(12) = {14, 13}; +Line(13) = {13, 12}; +Line(14) = {12, 11}; +Line(15) = {14, 4}; +Line(16) = {13, 3}; +Line(17) = {11, 1}; +Line(18) = {12, 2}; +Line(19) = {27, 26}; +Line(20) = {26, 26}; +Line(21) = {26, 6}; +Line(22) = {27, 7}; +Line(23) = {26, 5}; +Line(24) = {27, 5}; +Line Loop(26) = {12, 16, -2, -15}; +Plane Surface(26) = {26}; +Line Loop(28) = {1, 2, 3, 4}; +Plane Surface(28) = {28}; +Line Loop(30) = {17, -4, -18, 14}; +Plane Surface(30) = {30}; +Line Loop(32) = {11, 12, 13, 14}; +Plane Surface(32) = {32}; +Line Loop(34) = {15, -1, -17, 11}; +Plane Surface(34) = {34}; +Line Loop(36) = {16, 3, -18, -13}; +Plane Surface(36) = {36}; +Line Loop(38) = {5, -21, 23}; +Plane Surface(38) = {38}; +Line Loop(40) = {24, -23, -19}; +Plane Surface(40) = {40}; +Line Loop(42) = {24, -7, -22}; +Plane Surface(42) = {42}; +Line Loop(44) = {5, 6, 7}; +Plane Surface(44) = {44}; +Line Loop(46) = {21, 6, -22, 19}; +Plane Surface(46) = {46}; +Surface Loop(48) = {38, 44, 46, 42, 40}; +Volume(48) = {48}; +Surface Loop(50) = {36, 26, 32, 34, 28, 30}; +Volume(50) = {50}; +Physical Surface("top_surface") = {46}; +Physical Surface("bottom_surface") = {34}; +Physical Surface("bottom_dummy") = {30, 32, 26, 28}; +Physical Surface("top_dummy") = {40, 38, 44, 42}; +Physical Surface("master") = {36}; +Physical Volume("top_body") = {48}; +Physical Volume("bottom_body") = {50}; diff --git a/examples/explicit/CMakeLists.txt b/examples/explicit/CMakeLists.txt new file mode 100644 index 000000000..744b63528 --- /dev/null +++ b/examples/explicit/CMakeLists.txt @@ -0,0 +1,40 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Nicolas Richart +# @author Cyprien Wolff +# +# @date creation: Mon Apr 16 2012 +# @date last modification: Thu Nov 01 2012 +# +# @brief configuration for explicit example +# +# @section LICENSE +# +# Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +register_example(explicit_dynamic explicit_dynamic.cc) + +add_mesh(explicit_dynamic_mesh bar.geo 3 1) +add_dependencies(explicit_dynamic explicit_dynamic_mesh) + +#=============================================================================== +file(COPY material.dat DESTINATION .) diff --git a/examples/explicit/bar.geo b/examples/explicit/bar.geo new file mode 100644 index 000000000..97b781841 --- /dev/null +++ b/examples/explicit/bar.geo @@ -0,0 +1,35 @@ +cl = 0.2; +Point(101) = {-5, 0, 0, cl}; +Point(102) = { 5, 0, 0, cl}; +Point(103) = { 5, 1, 0, cl}; +Point(104) = {-5, 1, 0, cl}; +Point(105) = {-5, 0, 1, cl}; +Point(106) = { 5, 0, 1, cl}; +Point(110) = { 5, 1, 1, cl}; +Point(114) = {-5, 1, 1, cl}; +Line(101) = {101, 102}; +Line(102) = {102, 103}; +Line(103) = {103, 104}; +Line(104) = {104, 101}; +Line(106) = {105, 106}; +Line(107) = {106, 110}; +Line(108) = {110, 114}; +Line(109) = {114, 105}; +Line(111) = {101, 105}; +Line(112) = {102, 106}; +Line(116) = {103, 110}; +Line(120) = {104, 114}; +Line Loop(101) = {101, 102, 103, 104}; +Plane Surface(101) = {101}; +Line Loop(113) = {101, 112, -106, -111}; +Ruled Surface(113) = {113}; +Line Loop(117) = {102, 116, -107, -112}; +Ruled Surface(117) = {117}; +Line Loop(121) = {103, 120, -108, -116}; +Ruled Surface(121) = {121}; +Line Loop(125) = {104, 111, -109, -120}; +Ruled Surface(125) = {125}; +Line Loop(126) = {106, 107, 108, 109}; +Plane Surface(126) = {126}; +Surface Loop(1) = {101, 126, 113, 117, 121, 125}; +Volume(1) = {1}; diff --git a/examples/explicit/explicit_dynamic.cc b/examples/explicit/explicit_dynamic.cc new file mode 100644 index 000000000..314317be3 --- /dev/null +++ b/examples/explicit/explicit_dynamic.cc @@ -0,0 +1,109 @@ +/** + * @file explicit_dynamic.cc + * + * @author Seyedeh Mohadeseh Taheri Mousavi + * + * @date creation: Mon Apr 16 2012 + * @date last modification: Tue Jun 10 2014 + * + * @brief This code refers to the explicit dynamic example from the user manual + * + * @section LICENSE + * + * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include "solid_mechanics_model.hh" + +#include + +using namespace akantu; + + +int main(int argc, char *argv[]) { + initialize("material.dat", argc, argv); + + const UInt spatial_dimension = 3; + const Real pulse_width = 2.; + const Real A = 0.01; + Real time_step; + Real time_factor = 0.8; + UInt max_steps = 1000; + + Mesh mesh(spatial_dimension); + mesh.computeBoundingBox(); + + + mesh.read("bar.msh"); + + SolidMechanicsModel model(mesh); + + /// model initialization + model.initFull(); + + time_step = model.getStableTimeStep(); + std::cout << "Time Step = " << time_step * time_factor << "s ("<< time_step << "s)" << std::endl; + model.setTimeStep(time_step * time_factor); + + /// boundary and initial conditions + Array & displacement = model.getDisplacement(); + const Array & nodes = mesh.getNodes(); + + for (UInt n = 0; n < mesh.getNbNodes(); ++n) { + Real x = nodes(n); + // Sinus * Gaussian + Real L = pulse_width; + Real k = 0.1 * 2 * M_PI * 3 / L; + displacement(n) = A * sin(k * x) * exp(-(k * x) * (k * x) / (L * L)); + } + + std::ofstream energy; + energy.open("energy.csv"); + + energy << "id,rtime,epot,ekin,tot" << std::endl; + + model.setBaseName("explicit_dynamic"); + model.addDumpField("displacement"); + model.addDumpField("velocity" ); + model.addDumpField("acceleration"); + model.addDumpField("stress" ); + model.dump(); + + for(UInt s = 1; s <= max_steps; ++s) { + model.solveStep(); + + Real epot = model.getPotentialEnergy(); + Real ekin = model.getKineticEnergy(); + + energy << s << "," << s*time_step << "," + << epot << "," + << ekin << "," + << epot + ekin << "," + << std::endl; + + if(s % 10 == 0) std::cout << "passing step " << s << "/" << max_steps << std::endl; + model.dump(); + } + + energy.close(); + + finalize(); + + return EXIT_SUCCESS; +} diff --git a/examples/explicit/material.dat b/examples/explicit/material.dat new file mode 100644 index 000000000..1f87cce23 --- /dev/null +++ b/examples/explicit/material.dat @@ -0,0 +1,7 @@ +material elastic [ + name = steel + rho = 7800 # density + E = 2.1e11 # young's modulus + nu = 0.0 # poisson's ratio +] + diff --git a/examples/heat_transfer/CMakeLists.txt b/examples/heat_transfer/CMakeLists.txt new file mode 100644 index 000000000..01a75abb7 --- /dev/null +++ b/examples/heat_transfer/CMakeLists.txt @@ -0,0 +1,42 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Guillaume Anciaux +# +# @date creation: Fri Jun 06 2014 +# @date last modification: Fri Jun 06 2014 +# +# @brief configuration for heat transfer example +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +register_example(explicit_heat_transfer explicit_heat_transfer.cc) + +add_mesh(explicit_heat_transfer_mesh square.geo 2 2) +add_dependencies(explicit_dynamic explicit_heat_transfer_mesh) + + +#=============================================================================== +file(COPY material.dat DESTINATION .) + +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/paraview) diff --git a/examples/heat_transfer/explicit_heat_transfer.cc b/examples/heat_transfer/explicit_heat_transfer.cc new file mode 100644 index 000000000..da251ad94 --- /dev/null +++ b/examples/heat_transfer/explicit_heat_transfer.cc @@ -0,0 +1,113 @@ +/** + * @file explicit_heat_transfer.cc + * + * @author Guillaume Anciaux + * + * @date creation: Fri Jun 06 2014 + * @date last modification: Fri Jun 06 2014 + * + * @brief test of the class HeatTransferModel on the 3d cube + * + * @section LICENSE + * + * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include "heat_transfer_model.hh" +#include "pbc_synchronizer.hh" +/* -------------------------------------------------------------------------- */ +#include +#include +#include +using namespace std; + +/* -------------------------------------------------------------------------- */ +akantu::UInt spatial_dimension = 2; + +std::string base_name; + +int main(int argc, char *argv[]) +{ + akantu::initialize("material.dat", argc, argv); + + //create mesh + akantu::Mesh mesh(spatial_dimension); + mesh.read("square.msh"); + + akantu::HeatTransferModel model(mesh); + //initialize everything + model.initFull(); + + //assemble the lumped capacity + model.assembleCapacityLumped(); + + //get stable time step + akantu::Real time_step = model.getStableTimeStep()*0.8; + cout<<"time step is:" << time_step << endl; + model.setTimeStep(time_step); + + //boundary conditions + const akantu::Array & nodes = model.getFEEngine().getMesh().getNodes(); + akantu::Array & boundary = model.getBlockedDOFs(); + akantu::Array & temperature = model.getTemperature(); + double length; + length = 1.; + akantu::UInt nb_nodes = model.getFEEngine().getMesh().getNbNodes(); + for (akantu::UInt i = 0; i < nb_nodes; ++i) { + temperature(i) = 100.; + + akantu::Real dx = nodes(i,0) - length/4.; + akantu::Real dy = 0.0; + akantu::Real dz = 0.0; + + if (spatial_dimension > 1) dy = nodes(i,1) - length/4.; + if (spatial_dimension == 3) dz = nodes(i,2) - length/4.; + akantu::Real d = sqrt(dx*dx + dy*dy + dz*dz); + // if(dx < 0.0){ + if(d < 0.1){ + boundary(i) = true; + temperature(i) = 300.; + } + } + + model.updateResidual(); + model.setBaseName("heat_transfer_square2d"); + model.addDumpField("temperature" ); + model.addDumpField("temperature_rate"); + model.addDumpField("residual" ); + model.addDumpField("capacity_lumped" ); + model.dump(); + + //main loop + int max_steps = 15000; + for(int i=0; i +# +# @date creation: Fri Feb 24 2012 +# @date last modification: Thu Jun 05 2014 +# +# @brief configuration implicit tests +# +# @section LICENSE +# +# Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +#=============================================================================== +register_example(implicit_dynamic implicit_dynamic.cc) + +add_mesh(implicit_dynamic_mesh beam.geo 3 2) +add_dependencies(implicit_dynamic implicit_dynamic_mesh) + +#=============================================================================== +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/material_dynamic.dat + ${CMAKE_CURRENT_BINARY_DIR}/material_dynamic.dat + COPYONLY + ) diff --git a/examples/implicit/beam.geo b/examples/implicit/beam.geo new file mode 100644 index 000000000..c0bd7bced --- /dev/null +++ b/examples/implicit/beam.geo @@ -0,0 +1,26 @@ +h = 0.1; + +Point(1) = {0, 0, 0, h}; +Point(2) = {10, 0, 0, h}; +Point(3) = {10, 1, 0, h}; +Point(4) = {0, 1, 0, h}; +Point(6) = {0, 0.5, 0, h}; +Point(7) = {10, 0.5, 0, h}; +Point(5) = {5, 0.5, 0, h}; +Line(1) = {1, 2}; +Line(21) = {2, 7}; +Line(22) = {7, 3}; +Line(3) = {3, 4}; +Line(41) = {4, 6}; +Line(42) = {6, 1}; +Line Loop(5) = {3, 41, 42, 1, 21, 22}; +Plane Surface(6) = {5}; + +Point{5} In Surface{6}; + +Physical Point ("traction") = {5}; +Physical Point ("blocked") = {6}; +Physical Point ("roller") = {7}; +Physical Surface("bulk") = {6}; +Physical Line ("left") = {41, 42}; +Physical Line ("right") = {21, 22}; diff --git a/examples/implicit/implicit_dynamic.cc b/examples/implicit/implicit_dynamic.cc new file mode 100644 index 000000000..9fadb07f6 --- /dev/null +++ b/examples/implicit/implicit_dynamic.cc @@ -0,0 +1,147 @@ +/** + * @file implicit_dynamic.cc + * + * @author Nicolas Richart + * + * @date creation: Fri Feb 24 2012 + * @date last modification: Thu Jun 05 2014 + * + * @brief This code refers to the implicit dynamic example from the user manual + * + * @section LICENSE + * + * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include "solid_mechanics_model.hh" + +#include +using namespace akantu; + +/* -------------------------------------------------------------------------- */ +const Real bar_length = 10.; +const Real bar_height = 1.; +const Real bar_depth = 1.; +const Real F = 5e3; +const Real L = bar_length; +const Real I = bar_depth * bar_height * bar_height * bar_height / 12.; +const Real E = 12e7; +const Real rho = 1000; +const Real m = rho * bar_height * bar_depth; + +static Real w(UInt n) { + return n*n*M_PI*M_PI/(L*L)*sqrt(E*I/m); +} + +static Real analytical_solution(Real time) { + return 2*F*L*L*L/(pow(M_PI, 4)*E*I) * ((1. - cos(w(1)*time)) + (1. - cos(w(3)*time))/81. + (1. - cos(w(5)*time))/625.); +} + +const UInt spatial_dimension = 2; +const Real time_step = 1e-4; +const Real max_time = 0.62; +/* -------------------------------------------------------------------------- */ +int main(int argc, char *argv[]) { + + initialize("material_dynamic.dat", argc, argv); + + Mesh mesh(spatial_dimension); + + StaticCommunicator & comm = StaticCommunicator::getStaticCommunicator(); + Int psize = comm.getNbProc(); + Int prank = comm.whoAmI(); + + MeshPartition * partition = NULL; + if(prank == 0) { + mesh.read("beam.msh"); + partition = new MeshPartitionScotch(mesh, spatial_dimension); + partition->partitionate(psize); + } + + SolidMechanicsModel model(mesh); + model.initParallel(partition); + mesh.createGroupsFromMeshData("physical_names"); + + /// model initialization + model.initFull(SolidMechanicsModelOptions(_implicit_dynamic)); + Material &mat = model.getMaterial(0); + mat.setParam("E", E); + mat.setParam("rho", rho); + + model.getMassMatrix().saveMatrix("M.mtx"); + + Array & force = model.getForce(); + Array & displacment = model.getDisplacement(); + + // boundary conditions + model.applyBC(BC::Dirichlet::FixedValue(0.0, _x), "blocked"); + model.applyBC(BC::Dirichlet::FixedValue(0.0, _y), "blocked"); + model.applyBC(BC::Dirichlet::FixedValue(0.0, _y), "roller"); + + const Array & trac_nodes = mesh.getElementGroup("traction").getNodes(); + + bool dump_node = false; + if(trac_nodes.getSize() > 0 && mesh.isLocalOrMasterNode(trac_nodes(0))) { + force(trac_nodes(0), 1) = F; + dump_node = true; + } + + // output setup + std::ofstream pos; + pos.open("position.csv"); + if(!pos.good()) AKANTU_DEBUG_ERROR("Cannot open file \"position.csv\""); + + pos << "id,time,position,solution" << std::endl; + + model.setBaseName("dynamic"); + model.addDumpFieldVector("displacement"); + model.addDumpField("velocity" ); + model.addDumpField("acceleration"); + model.addDumpField("force" ); + model.addDumpField("residual" ); + model.dump(); + + + model.setTimeStep(time_step); + + /// time loop + Real time = 0.; + for (UInt s = 1; time < max_time; ++s, time += time_step) { + if(prank == 0) + std::cout << s << "\r" << std::flush; + + model.solveStep<_scm_newton_raphson_tangent_modified, _scc_increment>(1e-12, 100); + + if(dump_node) + pos << s << "," + << time << "," + << displacment(trac_nodes(0), 1) << "," + << analytical_solution(s*time_step) << std::endl; + + if(s % 100 == 0) + model.dump(); + } + + std::cout << std::endl; + pos.close(); + + finalize(); + + return EXIT_SUCCESS; +} diff --git a/examples/implicit/material_dynamic.dat b/examples/implicit/material_dynamic.dat new file mode 100644 index 000000000..7a1337374 --- /dev/null +++ b/examples/implicit/material_dynamic.dat @@ -0,0 +1,6 @@ +material elastic [ + name = fictif + rho = 1000 # density + E = 12e7 # young's modulus + nu = 0.3 # poisson's ratio +] diff --git a/examples/new_material/CMakeLists.txt b/examples/new_material/CMakeLists.txt new file mode 100644 index 000000000..061d6f258 --- /dev/null +++ b/examples/new_material/CMakeLists.txt @@ -0,0 +1,48 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Seyedeh Mohadeseh Taheri Mousavi +# +# @date creation: Fri Apr 20 2012 +# @date last modification: Thu Nov 01 2012 +# +# @brief CMakeFile for new material example +# +# @section LICENSE +# +# Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +#=============================================================================== + +add_mesh(new_local_material_barre_trou_mesh barre_trou.geo 2 2) + +register_example(new_local_material local_material_damage.cc new_local_material.cc) +add_dependencies(new_local_material + new_local_material_barre_trou_mesh + ) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/material.dat + ${CMAKE_CURRENT_BINARY_DIR}/material.dat + COPYONLY + ) + +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/paraview) diff --git a/examples/new_material/barre_trou.geo b/examples/new_material/barre_trou.geo new file mode 100644 index 000000000..8df890782 --- /dev/null +++ b/examples/new_material/barre_trou.geo @@ -0,0 +1,31 @@ +lz = 0.1; +Point (1) = {0.00, 0, 0, lz}; +Point (2) = {10, 0, 0, lz}; +Point (3) = {10, 4, 0,lz}; +Point (4) = {0.0 , 4,0, lz}; + +Line (1) = {1, 2}; +Line (2) = {2, 3}; +Line (3) = {3, 4}; +Line (4) = {4, 1}; +Line Loop (6) = {1,2, 3, 4}; + + + +Point(5) = {5, 2, 0,lz}; +Point(6) = {3.5, 2, 0,lz}; +Point(8) = {6.5, 2, 0,lz}; +Point(9) = {5, 0.5, 0,lz}; +Point(11) = {5, 3.5, 0,lz}; +Point(12) = {5, 3.5, 0,lz}; +Circle(7) = {6, 5, 11}; +Circle(8) = {11, 5, 8}; +Circle(9) = {8, 5, 9}; +Circle(10) = {9, 5, 6}; +Line Loop(11) = {10, 9, 8, 7}; +Plane Surface(11)={6,11}; +Physical Surface("Interior") = {11}; +Physical Line("Traction") = {2}; +Physical Line("Fixed_x") = {4}; +Physical Line("Fixed_y") = {1, 3}; +Physical Line("Free") = {7, 8, 9, 10}; diff --git a/examples/new_material/local_material_damage.cc b/examples/new_material/local_material_damage.cc new file mode 100644 index 000000000..ee1c0b53d --- /dev/null +++ b/examples/new_material/local_material_damage.cc @@ -0,0 +1,106 @@ +/** + * @file local_material_damage.cc + * + * @author Guillaume Anciaux + * @author Nicolas Richart + * @author Marion Estelle Chambart + * + * @date creation: Fri Nov 26 2010 + * @date last modification: Tue Jun 24 2014 + * + * @brief Specialization of the material class for the damage material + * + * @section LICENSE + * + * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include "local_material_damage.hh" +#include "solid_mechanics_model.hh" + +__BEGIN_AKANTU__ + +/* -------------------------------------------------------------------------- */ +LocalMaterialDamage::LocalMaterialDamage(SolidMechanicsModel & model, + const ID & id) : + Material(model, id), + damage("damage", *this) { + AKANTU_DEBUG_IN(); + + this->registerParam("E" , E , 0. , _pat_parsable, "Young's modulus" ); + this->registerParam("nu" , nu , 0.5 , _pat_parsable, "Poisson's ratio" ); + this->registerParam("lambda" , lambda , _pat_readable, "First Lamé coefficient" ); + this->registerParam("mu" , mu , _pat_readable, "Second Lamé coefficient"); + this->registerParam("kapa" , kpa , _pat_readable, "Bulk coefficient" ); + this->registerParam("Yd" , Yd , 50., _pat_parsmod); + this->registerParam("Sd" , Sd , 5000., _pat_parsmod); + + damage.initialize(1); + + AKANTU_DEBUG_OUT(); +} + +/* -------------------------------------------------------------------------- */ +void LocalMaterialDamage::initMaterial() { + AKANTU_DEBUG_IN(); + Material::initMaterial(); + + lambda = nu * E / ((1 + nu) * (1 - 2*nu)); + mu = E / (2 * (1 + nu)); + kpa = lambda + 2./3. * mu; + + AKANTU_DEBUG_OUT(); +} + +/* -------------------------------------------------------------------------- */ +void LocalMaterialDamage::computeStress(ElementType el_type, GhostType ghost_type) { + AKANTU_DEBUG_IN(); + + Real * dam = damage(el_type, ghost_type).storage(); + + MATERIAL_STRESS_QUADRATURE_POINT_LOOP_BEGIN(el_type, ghost_type); + + computeStressOnQuad(grad_u, sigma, *dam); + ++dam; + + MATERIAL_STRESS_QUADRATURE_POINT_LOOP_END; + + AKANTU_DEBUG_OUT(); +} + +/* -------------------------------------------------------------------------- */ +void LocalMaterialDamage::computePotentialEnergy(ElementType el_type, GhostType ghost_type) { + AKANTU_DEBUG_IN(); + + Material::computePotentialEnergy(el_type, ghost_type); + + if(ghost_type != _not_ghost) return; + Real * epot = potential_energy(el_type).storage(); + + MATERIAL_STRESS_QUADRATURE_POINT_LOOP_BEGIN(el_type, ghost_type); + computePotentialEnergyOnQuad(grad_u, sigma, *epot); + epot++; + MATERIAL_STRESS_QUADRATURE_POINT_LOOP_END; + + AKANTU_DEBUG_OUT(); +} + +/* -------------------------------------------------------------------------- */ + +__END_AKANTU__ diff --git a/examples/new_material/local_material_damage.hh b/examples/new_material/local_material_damage.hh new file mode 100644 index 000000000..dabfcdae3 --- /dev/null +++ b/examples/new_material/local_material_damage.hh @@ -0,0 +1,128 @@ +/** + * @file local_material_damage.hh + * + * @author Guillaume Anciaux + * @author Nicolas Richart + * @author Marion Estelle Chambart + * + * @date creation: Fri Nov 26 2010 + * @date last modification: Fri May 16 2014 + * + * @brief Material isotropic elastic + * + * @section LICENSE + * + * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include "aka_common.hh" +#include "material.hh" +/* -------------------------------------------------------------------------- */ + +#ifndef __AKANTU_LOCAL_MATERIAL_DAMAGE_HH__ +#define __AKANTU_LOCAL_MATERIAL_DAMAGE_HH__ + +__BEGIN_AKANTU__ + +class LocalMaterialDamage : public Material { + /* ------------------------------------------------------------------------ */ + /* Constructors/Destructors */ + /* ------------------------------------------------------------------------ */ +public: + + LocalMaterialDamage(SolidMechanicsModel & model, const ID & id = ""); + + virtual ~LocalMaterialDamage() {}; + + /* ------------------------------------------------------------------------ */ + /* Methods */ + /* ------------------------------------------------------------------------ */ +public: + + void initMaterial(); + + /// constitutive law for all element of a type + void computeStress(ElementType el_type, GhostType ghost_type = _not_ghost); + + /// constitutive law for a given quadrature point + inline void computeStressOnQuad(Matrix & grad_u, + Matrix & sigma, + Real & damage); + + /// compute tangent stiffness + virtual void computeTangentStiffness(__attribute__ ((unused)) const ElementType & el_type, + __attribute__ ((unused)) Array & tangent_matrix, + __attribute__ ((unused)) GhostType ghost_type = _not_ghost) {}; + + /// compute the potential energy for all elements + void computePotentialEnergy(ElementType el_type, GhostType ghost_type = _not_ghost); + + /// compute the potential energy for on element + inline void computePotentialEnergyOnQuad(Matrix & grad_u, + Matrix & sigma, + Real & epot); + + /* ------------------------------------------------------------------------ */ + /* Accessors */ + /* ------------------------------------------------------------------------ */ +public: + /// compute the celerity of wave in the material + inline Real getCelerity(const Element & element) const; + + /* ------------------------------------------------------------------------ */ + /* Class Members */ + /* ------------------------------------------------------------------------ */ + + AKANTU_GET_MACRO_BY_ELEMENT_TYPE_CONST(Damage, damage, Real); +private: + + /// the young modulus + Real E; + + /// Poisson coefficient + Real nu; + + /// First Lamé coefficient + Real lambda; + + /// Second Lamé coefficient (shear modulus) + Real mu; + + /// resistance to damage + Real Yd; + + /// damage threshold + Real Sd; + + /// Bulk modulus + Real kpa; + + /// damage internal variable + InternalField damage; + +}; + +/* -------------------------------------------------------------------------- */ +/* inline functions */ +/* -------------------------------------------------------------------------- */ +#include "local_material_damage_inline_impl.cc" + +__END_AKANTU__ + +#endif /* __AKANTU_LOCAL_MATERIAL_DAMAGE_HH__ */ diff --git a/examples/new_material/local_material_damage_inline_impl.cc b/examples/new_material/local_material_damage_inline_impl.cc new file mode 100644 index 000000000..2d8d5ccf0 --- /dev/null +++ b/examples/new_material/local_material_damage_inline_impl.cc @@ -0,0 +1,80 @@ +/** + * @file local_material_damage_inline_impl.cc + * + * @author Guillaume Anciaux + * @author Nicolas Richart + * @author Marion Estelle Chambart + * + * @date creation: Fri Nov 26 2010 + * @date last modification: Fri May 16 2014 + * + * @brief Implementation of the inline functions of the material damage + * + * @section LICENSE + * + * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ + + +/* -------------------------------------------------------------------------- */ +inline void LocalMaterialDamage::computeStressOnQuad(Matrix & grad_u, + Matrix & sigma, + Real & dam) { + + Real trace = grad_u.trace(); + + /// \sigma_{ij} = \lambda * (\nabla u)_{kk} * \delta_{ij} + \mu * (\nabla u_{ij} + \nabla u_{ji}) + for (UInt i = 0; i < spatial_dimension; ++i) { + for (UInt j = 0; j < spatial_dimension; ++j) { + sigma(i, j) = (i == j)*lambda*trace + mu*(grad_u(i, j) + grad_u(j, i)); + } + } + + Real Y = 0; + for (UInt i = 0; i < spatial_dimension; ++i) { + for (UInt j = 0; j < spatial_dimension; ++j) { + Y += sigma(i,j) * grad_u(i,j); + } + } + Y *= 0.5; + + Real Fd = Y - Yd - Sd*dam; + + if (Fd > 0) dam = (Y - Yd) / Sd; + dam = std::min(dam,1.); + + sigma *= 1-dam; +} + +/* -------------------------------------------------------------------------- */ +inline void LocalMaterialDamage::computePotentialEnergyOnQuad(Matrix & grad_u, + Matrix & sigma, + Real & epot) { + epot = 0.; + for (UInt i = 0, t = 0; i < spatial_dimension; ++i) + for (UInt j = 0; j < spatial_dimension; ++j, ++t) + epot += sigma(i, j) * (grad_u(i, j) - (i == j)); + epot *= .5; +} + +/* -------------------------------------------------------------------------- */ +inline Real LocalMaterialDamage::getCelerity(__attribute__ ((unused)) const Element & element) const { + return (std::sqrt(E/rho)); +} diff --git a/examples/new_material/material.dat b/examples/new_material/material.dat new file mode 100644 index 000000000..662bae263 --- /dev/null +++ b/examples/new_material/material.dat @@ -0,0 +1,6 @@ +material local_damage [ + name = concrete + rho = 3000 # density + E = 40e9 # young's modulus + nu = 0.2 # poisson's ratio +] diff --git a/examples/new_material/new_local_material.cc b/examples/new_material/new_local_material.cc new file mode 100644 index 000000000..ef503e9b5 --- /dev/null +++ b/examples/new_material/new_local_material.cc @@ -0,0 +1,109 @@ +/** + * @file new_local_material.cc + * + * @author Guillaume Anciaux + * @author Nicolas Richart + * @author Marion Estelle Chambart + * + * @date creation: Fri Apr 20 2012 + * @date last modification: Mon Apr 07 2014 + * + * @brief test of the class SolidMechanicsModel + * + * @section LICENSE + * + * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include + +/* -------------------------------------------------------------------------- */ +#include "solid_mechanics_model.hh" +#include "local_material_damage.hh" + +using namespace akantu; + +#define bar_length 10. +#define bar_height 4. +akantu::Real eps = 1e-10; + +int main(int argc, char *argv[]) { + akantu::initialize("material.dat", argc, argv); + + UInt max_steps = 10000; + Real epot, ekin; + + const UInt spatial_dimension = 2; + + Mesh mesh(spatial_dimension); + mesh.read("barre_trou.msh"); + mesh.createGroupsFromMeshData("physical_names"); + + /// model creation + SolidMechanicsModel model(mesh); + + /// model initialization + model.initFull(SolidMechanicsModelOptions(_explicit_lumped_mass, true)); + model.registerNewCustomMaterials("local_damage"); + model.initMaterials(); + + std::cout << model.getMaterial(0) << std::endl; + + Real time_step = model.getStableTimeStep(); + model.setTimeStep(time_step/10.); + + /// Dirichlet boundary conditions + model.applyBC(BC::Dirichlet::FixedValue(0.0, _x), "Fixed_x"); + model.applyBC(BC::Dirichlet::FixedValue(0.0, _y), "Fixed_y"); + + // Neumann boundary condition + Matrix stress(2,2); + stress.eye(3e2); + model.applyBC(BC::Neumann::FromStress(stress), "Traction"); + + model.setBaseName("local_material"); + model.addDumpField("displacement"); + model.addDumpField("velocity" ); + model.addDumpField("acceleration"); + model.addDumpField("force" ); + model.addDumpField("residual" ); + model.addDumpField("grad_u" ); + model.addDumpField("stress" ); + model.addDumpField("damage" ); + model.dump(); + + for(UInt s = 0; s < max_steps; ++s) { + model.explicitPred(); + + model.updateResidual(); + model.updateAcceleration(); + model.explicitCorr(); + + epot = model.getPotentialEnergy(); + ekin = model.getKineticEnergy(); + + if(s % 100 == 0) std::cout << s << " " << epot << " " << ekin << " " << epot + ekin + << std::endl; + + if(s % 100 == 0) model.dump(); + } + + akantu::finalize(); + return EXIT_SUCCESS; +} diff --git a/examples/optimization/CMakeLists.txt b/examples/optimization/CMakeLists.txt new file mode 100644 index 000000000..49241bdcf --- /dev/null +++ b/examples/optimization/CMakeLists.txt @@ -0,0 +1,32 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Alejandro M. Aragón +# +# @date Mon Mar 24 11:30:00 2014 +# +# @brief configuration file for contact examples +# +# @section LICENSE +# +# Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +register_example(fn_optimize fn_optimize.cc) diff --git a/examples/optimization/fn_optimize.cc b/examples/optimization/fn_optimize.cc new file mode 100644 index 000000000..3855de530 --- /dev/null +++ b/examples/optimization/fn_optimize.cc @@ -0,0 +1,101 @@ +/** + * @file fn_optimize.cc + * + * @author Alejandro M. Aragón + * + * @date Thu May 22 14:12:00 2014 + * + * @brief File used to show how to use the NLopt optimizator to find the + * minimum of a function + * + * @section LICENSE + * + * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +#include +#include + +#include "aka_optimize.hh" + + +typedef struct { + double a, b; +} my_constraint_data; + + +//! Functor used for the evaluation of the function and its gradient +class Functor { + + int count_; //!< Function evaluation counter + +public: + + //! Default constructor + Functor() : count_() {} + + //! Return function evaluation counter + int count() const + { return count_; } + + double operator()(const std::vector &x, std::vector &grad) + { + ++count_; + if (!grad.empty()) { + grad[0] = 0.0; + grad[1] = 0.5 / sqrt(x[1]); + } + return sqrt(x[1]); + } + + static double wrap(const std::vector &x, std::vector &grad, void *data) { + return (*reinterpret_cast(data))(x, grad); } + +}; + + +double myvconstraint(const std::vector &x, std::vector &grad, void *data) +{ + my_constraint_data *d = reinterpret_cast(data); + double a = d->a, b = d->b; + if (!grad.empty()) { + grad[0] = 3 * a * (a*x[0] + b) * (a*x[0] + b); + grad[1] = -1.0; + } + return ((a*x[0] + b) * (a*x[0] + b) * (a*x[0] + b) - x[1]); +} + + +int main(int argc, char *argv[]) { + + my_constraint_data data[2] = { {2,0}, {-1,1} }; + + std::vector x(2); + x[0] = 1.234; x[1] = 5.678; + + Functor fn; + akantu::Optimizator ofn(x, fn); + + ofn.add_inequality_constraint(myvconstraint, &data[0], 1e-8); + ofn.add_inequality_constraint(myvconstraint, &data[1], 1e-8); + + ofn.result(); + std::cout<<"\nTotal function evaluations: "< +# +# @date creation: Fri Oct 22 2010 +# @date last modification: Thu Nov 01 2012 +# +# @brief configuration for a parallel example +# +# @section LICENSE +# +# Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +#=============================================================================== +add_mesh(parallel_2d_mesh square_2d.geo 2 1) + +register_example(parallel_2d + parallel_2d.cc) +add_dependencies(parallel_2d + parallel_2d_mesh) + +#=============================================================================== +file(COPY material.dat DESTINATION .) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/paraview) \ No newline at end of file diff --git a/examples/parallel_2d/material.dat b/examples/parallel_2d/material.dat new file mode 100644 index 000000000..781c77d73 --- /dev/null +++ b/examples/parallel_2d/material.dat @@ -0,0 +1,6 @@ +material elastic [ + name = steel + rho = 7800 # density + E = 2.1e11 # young's modulus + nu = 0.3 # poisson's ratio +] diff --git a/examples/parallel_2d/parallel_2d.cc b/examples/parallel_2d/parallel_2d.cc new file mode 100644 index 000000000..592196195 --- /dev/null +++ b/examples/parallel_2d/parallel_2d.cc @@ -0,0 +1,125 @@ +/** + * @file parallel_2d.cc + * + * @author Nicolas Richart + * + * @date creation: Fri Oct 22 2010 + * @date last modification: Tue Jun 24 2014 + * + * @brief Parallel example + * + * @section LICENSE + * + * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ + +/* -------------------------------------------------------------------------- */ +#include +#include + +/* -------------------------------------------------------------------------- */ +#include "mesh_io.hh" +#include "solid_mechanics_model.hh" +/* -------------------------------------------------------------------------- */ +using namespace akantu; + +int main(int argc, char *argv[]) +{ + initialize("material.dat", argc, argv); + debug::setDebugLevel(dblError); + + UInt spatial_dimension = 2; + UInt max_steps = 10000; + Real time_factor = 0.8; + Real max_disp = 1e-6; + + Mesh mesh(spatial_dimension); + + StaticCommunicator & comm = StaticCommunicator::getStaticCommunicator(); + Int psize = comm.getNbProc(); + Int prank = comm.whoAmI(); + + akantu::MeshPartition * partition = NULL; + if(prank == 0) { + // Read the mesh + mesh.read("square_2d.msh"); + partition = new MeshPartitionScotch(mesh, spatial_dimension); + partition->partitionate(psize); + } + + SolidMechanicsModel model(mesh); + + /// model initialization + model.initParallel(partition); + delete partition; + + model.initFull(); + + if(prank == 0) std::cout << model.getMaterial(0) << std::endl; + + model.setBaseName("multi"); + model.addDumpFieldVector("displacement"); + model.addDumpFieldVector("velocity"); + model.addDumpFieldVector("acceleration"); + model.addDumpFieldTensor("stress"); + model.addDumpFieldTensor("grad_u"); + + /// boundary conditions + Real eps = 1e-16; + const Array & pos = mesh.getNodes(); + Array & disp = model.getDisplacement(); + Array & boun = model.getBlockedDOFs(); + + mesh.computeBoundingBox(); + Real left_side = mesh.getLowerBounds()(0); + Real right_side = mesh.getUpperBounds()(0); + + for (UInt i = 0; i < mesh.getNbNodes(); ++i) { + if(std::abs(pos(i,0) - left_side) < eps) { + disp(i, 0) = max_disp; + boun(i, 0) = true; + } + + if(std::abs(pos(i,0) - right_side) < eps) { + disp(i, 0) = -max_disp; + boun(i, 0) = true; + } + } + + Real time_step = model.getStableTimeStep() * time_factor; + std::cout << "Time Step = " << time_step << "s" << std::endl; + model.setTimeStep(time_step); + + model.dump(); + for(UInt s = 1; s <= max_steps; ++s) { + model.explicitPred(); + model.updateResidual(); + model.updateAcceleration(); + model.explicitCorr(); + + if(s % 200 == 0) model.dump(); + + if(prank == 0 && s % 100 == 0) + std::cout << "passing step " << s << "/" << max_steps << std::endl; + } + + finalize(); + return EXIT_SUCCESS; +} diff --git a/examples/parallel_2d/square_2d.geo b/examples/parallel_2d/square_2d.geo new file mode 100644 index 000000000..7146ce074 --- /dev/null +++ b/examples/parallel_2d/square_2d.geo @@ -0,0 +1,26 @@ +// Element size +h = 0.05; + +// Dimension of square +L = 1; + +// ------------------------------------------ +// Geometry +// ------------------------------------------ + +// Points +Point(1) = {0, 0, 0, h}; +Point(2) = {L, 0, 0, h}; +Point(3) = {L, L, 0, h}; +Point(4) = {0, L, 0, h}; + +// Lines +Line(1) = {4, 1}; +Line(2) = {1, 2}; +Line(3) = {2, 3}; +Line(4) = {3, 4}; + +// Geometric and Physical Surface +Line Loop(6) = {4, 1, 2, 3}; +Plane Surface(6) = {6}; +Physical Surface(7) = {6}; diff --git a/examples/static/CMakeLists.txt b/examples/static/CMakeLists.txt new file mode 100644 index 000000000..5f1c6bf35 --- /dev/null +++ b/examples/static/CMakeLists.txt @@ -0,0 +1,44 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Nicolas Richart +# +# @date creation: Fri Jun 13 2014 +# @date last modification: Fri Jun 13 2014 +# +# @brief configuration implicit tests +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +#=============================================================================== +register_example(static static.cc) + +add_mesh(static_mesh square.geo 2 2) +add_dependencies(static static_mesh) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/material.dat + ${CMAKE_CURRENT_BINARY_DIR}/material.dat + COPYONLY + ) + diff --git a/examples/static/material.dat b/examples/static/material.dat new file mode 100644 index 000000000..bf3315480 --- /dev/null +++ b/examples/static/material.dat @@ -0,0 +1,10 @@ +A = pi * 0.05**2 / 4 +rho_t = 7750 +E_t = 200e9 + +material elastic [ + name = dummy + rho = rho_t * A * 2. + E = E_t * A + nu = 0. +] diff --git a/examples/static/square.geo b/examples/static/square.geo new file mode 100644 index 000000000..3c299d0ec --- /dev/null +++ b/examples/static/square.geo @@ -0,0 +1,29 @@ +// Mesh size +h = 0.005; + +// Dimensions of the square +Lx = 0.01; +Ly = 0.01; + +// ------------------------------------------ +// Geometry +// ------------------------------------------ +Point(1) = { 0.0, 0.0, 0.0, h}; +Point(2) = { Lx, 0.0, 0.0, h}; +Point(3) = { Lx, Ly, 0.0, h}; +Point(4) = { 0.0, Ly, 0.0, h}; + +Line(1) = {1, 2}; +Line(2) = {2, 3}; +Line(3) = {3, 4}; +Line(4) = {4, 1}; + +Line Loop(1) = {1:4}; + +Plane Surface(1) = {1}; + +Physical Surface(1) = {1}; +Physical Line("Fixed_y") = {1}; +Physical Line("Fixed_x") = {4}; +Physical Line("Traction") = {2}; +Physical Line("Free") = {3}; diff --git a/examples/static/static.cc b/examples/static/static.cc new file mode 100644 index 000000000..36999592b --- /dev/null +++ b/examples/static/static.cc @@ -0,0 +1,80 @@ +/** + * @file static.cc + * + * @author Nicolas Richart + * + * @date creation: Fri Feb 24 2012 + * @date last modification: Thu Jun 05 2014 + * + * @brief This code refers to the implicit static example from the user manual + * + * @section LICENSE + * + * Copyright (©) 2010-2012, 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include "solid_mechanics_model.hh" +/* -------------------------------------------------------------------------- */ + +using namespace akantu; + +#define bar_length 0.01 +#define bar_height 0.01 + +/* -------------------------------------------------------------------------- */ +int main(int argc, char *argv[]) { + initialize("material.dat", argc, argv); + + const UInt spatial_dimension = 2; + + Mesh mesh(spatial_dimension); + mesh.read("square.msh"); + mesh.createGroupsFromMeshData("physical_names"); + + SolidMechanicsModel model(mesh); + + /// model initialization + model.initFull(SolidMechanicsModelOptions(_static)); + + model.setBaseName("static"); + model.addDumpFieldVector("displacement"); + model.addDumpField("force" ); + model.addDumpField("residual"); + model.addDumpField("grad_u" ); + + /// Dirichlet boundary conditions + model.applyBC(BC::Dirichlet::FixedValue(0.0, _x), "Fixed_x"); + model.applyBC(BC::Dirichlet::FixedValue(0.0, _y), "Fixed_y"); + model.applyBC(BC::Dirichlet::FixedValue(0.0001, _y), "Traction"); + model.dump(); + + model.assembleStiffnessMatrix(); + model.getStiffnessMatrix().saveMatrix("stiffness.mtx"); + + bool converged = model.solveStep<_scm_newton_raphson_tangent_modified, _scc_increment>(1e-4, 2); + + if(!converged) + AKANTU_DEBUG_ERROR("Did not converged in 1 step"); + + model.dump(); + + finalize(); + + return EXIT_SUCCESS; +} diff --git a/examples/structural_mechanics/CMakeLists.txt b/examples/structural_mechanics/CMakeLists.txt new file mode 100644 index 000000000..57feda912 --- /dev/null +++ b/examples/structural_mechanics/CMakeLists.txt @@ -0,0 +1,40 @@ +#=============================================================================== +# @file CMakeLists.txt +# +# @author Fabian Barras +# +# @date creation: Thu Jun 12 2014 +# @date last modification: Thu Jun 12 2014 +# +# @brief configuration for structural mechanics example +# +# @section LICENSE +# +# Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) +# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) +# +# Akantu is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Akantu is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Akantu. If not, see . +# +# @section DESCRIPTION +# +#=============================================================================== + +#=============================================================================== +add_mesh(parallel_2d_mesh square_2d.geo 2 1) + +register_example(bernoulli_beam_2_exemple + bernoulli_beam_2_exemple.cc) + +#=============================================================================== +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/paraview) \ No newline at end of file diff --git a/examples/structural_mechanics/bernoulli_beam_2_exemple.cc b/examples/structural_mechanics/bernoulli_beam_2_exemple.cc new file mode 100644 index 000000000..c46275f87 --- /dev/null +++ b/examples/structural_mechanics/bernoulli_beam_2_exemple.cc @@ -0,0 +1,184 @@ +/** + * @file bernoulli_beam_2_exemple.cc + * + * @author Fabian Barras + * + * @date creation: Thu Jun 12 2014 + * @date last modification: Thu Jun 12 2014 + * + * @brief Computation of the analytical exemple 1.1 in the TGC vol 6 + * + * @section LICENSE + * + * Copyright (©) 2014 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include +#include + +/* -------------------------------------------------------------------------- */ +#include "aka_common.hh" +#include "mesh.hh" +#include "mesh_io.hh" +#include "mesh_io_msh.hh" +#include "structural_mechanics_model.hh" +#include "material.hh" +/* -------------------------------------------------------------------------- */ + +#define TYPE _bernoulli_beam_2 + +using namespace akantu; + +//Linear load function +static void lin_load(double * position, double * load, + __attribute__ ((unused)) Real * normal, __attribute__ ((unused)) UInt surface_id){ + memset(load,0,sizeof(Real)*3); + if (position[0]<=10){ + load[1]= -6000; + } +} + +int main(int argc, char *argv[]){ + initialize(argc, argv); + debug::setDebugLevel(dblWarning); + + /* -------------------------------------------------------------------------- */ + // Defining the mesh + + Mesh beams(2); + + UInt nb_nodes=3; + UInt nb_nodes_1=1; + UInt nb_nodes_2=nb_nodes-nb_nodes_1 - 1; + UInt nb_element=nb_nodes-1; + + Array & nodes = const_cast &>(beams.getNodes()); + nodes.resize(nb_nodes); + + beams.addConnectivityType(_bernoulli_beam_2); + Array & connectivity = const_cast &>(beams.getConnectivity(_bernoulli_beam_2)); + connectivity.resize(nb_element); + + for(UInt i=0; i & forces = model.getForce(); + Array & displacement = model.getDisplacement(); + Array & boundary = model.getBlockedDOFs(); + const Array & N_M = model.getStress(_bernoulli_beam_2); + + Array & element_material = model.getElementMaterial(_bernoulli_beam_2); + + forces.clear(); + displacement.clear(); + + for (UInt i = 0; i < nb_nodes_2; ++i) { + element_material(i+nb_nodes_1)=1; + } + + + forces(nb_nodes-1,2) += M; + + model.computeForcesFromFunction<_bernoulli_beam_2>(lin_load, _bft_traction); + + /* -------------------------------------------------------------------------- */ + // Defining the boundary conditions + + boundary(0,0) = true; + boundary(0,1) = true; + boundary(0,2) = true; + boundary(nb_nodes_1,1) = true; + boundary(nb_nodes-1,1) = true; + /* -------------------------------------------------------------------------- */ + // Solve + Real error; + + model.assembleStiffnessMatrix(); + + UInt count = 0; + + model.addDumpFieldVector("displacement"); + model.addDumpField("rotation"); + model.addDumpFieldVector("force"); + model.addDumpField("momentum"); + + do { + if(count != 0) std::cerr << count << " - " << error << std::endl; + model.updateResidual(); + model.solve(); + count++; + } while (!model.testConvergenceIncrement(1e-10, error) && count < 10); + std::cerr << count << " - " << error << std::endl; + + /* -------------------------------------------------------------------------- */ + // Post-Processing + + model.computeStresses(); + + std::cout<< " d1 = " << displacement(nb_nodes_1,2) << std::endl; + std::cout<< " d2 = " << displacement(nb_nodes-1,2) << std::endl; + std::cout<< " M1 = " << N_M(0,1) << std::endl; + std::cout<< " M2 = " << N_M(2*(nb_nodes-2),1) << std::endl; + + model.dump(); + + finalize(); +}