diff --git a/CMakeLists.txt b/CMakeLists.txt index 6962df61e..a1580ba94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,225 +1,231 @@ #=============================================================================== # @file CMakeLists.txt # @author Nicolas Richart <nicolas.richart@epfl.ch> # @date Fri Jun 11 09:46:59 2010 # # @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 <http://www.gnu.org/licenses/>. # # @section DESCRIPTION # #=============================================================================== #=============================================================================== # _ ,-, _ # ,--, /: :\/': :`\/: :\ # |`; ' `,' `.; `: | _ _ # | | | ' | |. | | | | # | : | F E | A S | T++ || __ _| | ____ _ _ __ | |_ _ _ # | :. | : | : | : | \ / _` | |/ / _` | '_ \| __| | | | # \__/: :.. : :.. | :.. | ) | (_| | < (_| | | | | |_| |_| | # `---',\___/,\___/ /' \__,_|_|\_\__,_|_| |_|\__|\__,_| # `==._ .. . /' # `-::-' #=============================================================================== #=============================================================================== # CMake Project #=============================================================================== cmake_minimum_required(VERSION 2.6) project(akantu) enable_language(CXX) #=============================================================================== # Misc. #=============================================================================== set(AKANTU_CMAKE_DIR "${CMAKE_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries.") INCLUDE(${AKANTU_CMAKE_DIR}/AkantuMacros.cmake) #=============================================================================== # Version Number #=============================================================================== # AKANTU version number. An even minor number corresponds to releases. set(AKANTU_MAJOR_VERSION 0) set(AKANTU_MINOR_VERSION 1) include(FindSubversion) if (EXISTS ${CMAKE_SOURCE_DIR}/.svn) if(SUBVERSION_FOUND) subversion_wc_info(${CMAKE_SOURCE_DIR} MY) set(AKANTU_BUILD_VERSION ${MY_WC_REVISION}) set(AKANTU_VERSION "${AKANTU_MAJOR_VERSION}.${AKANTU_MINOR_VERSION}.${AKANTU_BUILD_VERSION}" ) file(WRITE VERSION "${AKANTU_VERSION}\n") else(SUBVERSION_FOUND) MESSAGE(SEND_ERROR "SVN control files were found but no subversion executable is present... ") endif(SUBVERSION_FOUND) else(EXISTS ${CMAKE_SOURCE_DIR}/.svn) if(EXISTS ${CMAKE_SOURCE_DIR}/VERSION) FILE(STRINGS VERSION AKANTU_VERSION) else(EXISTS ${CMAKE_SOURCE_DIR}/VERSION) MESSAGE(SEND_ERROR "No SVN control file neither VERSION file could be found. How was this release made ?") endif(EXISTS ${CMAKE_SOURCE_DIR}/VERSION) endif(EXISTS ${CMAKE_SOURCE_DIR}/.svn) # Append the library version information to the library target properties if(NOT AKANTU_NO_LIBRARY_VERSION) set(AKANTU_LIBRARY_PROPERTIES ${AKANTU_LIBRARY_PROPERTIES} VERSION "${AKANTU_VERSION}" SOVERSION "${AKANTU_MAJOR_VERSION}.${AKANTU_MINOR_VERSION}" ) endif(NOT AKANTU_NO_LIBRARY_VERSION) #=============================================================================== # Options #=============================================================================== option(AKANTU_DEBUG "Compiles akantu with the debug messages" ON) option(AKANTU_DOCUMENTATION "Build source documentation using Doxygen." OFF) # features add_optional_package(BLAS "Use BLAS for arithmetic operations" OFF) # Debug if(NOT AKANTU_DEBUG) - add_definitions(-DAKANTU_NDEBUG) + list(APPEND AKANTU_DEFINITIONS AKANTU_NDEBUG) endif(NOT AKANTU_DEBUG) #=============================================================================== # Dependencies #=============================================================================== find_package(Boost REQUIRED) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) endif() add_all_packages(${CMAKE_SOURCE_DIR}/packages) if(AKANTU_SCOTCH) set(AKANTU_PARTITIONER ON) else() set(AKANTU_PARTITIONER OFF) endif() if(AKANTU_MUMPS) set(AKANTU_SOLVER ON) else() set(AKANTU_SOLVER OFF) endif() -#=============================================================================== -# Library +add_akantu_definitions() + #=============================================================================== add_subdirectory(src) #=============================================================================== # Documentation #=============================================================================== if(AKANTU_DOCUMENTATION) find_package(Doxygen REQUIRED) if(DOXYGEN_FOUND) set(DOXYGEN_WARNINGS NO) set(DOXYGEN_QUIET YES) if(CMAKE_VERBOSE_MAKEFILE) set(DOXYGEN_WARNINGS YES) set(DOXYGEN_QUIET NO) endif(CMAKE_VERBOSE_MAKEFILE) add_subdirectory(doc/doxygen) endif(DOXYGEN_FOUND) endif(AKANTU_DOCUMENTATION) #=============================================================================== # Tests #=============================================================================== ENABLE_TESTING() INCLUDE(CTest) INCLUDE(${AKANTU_CMAKE_DIR}/AkantuTestAndExamples.cmake) option(AKANTU_TESTS "Activate tests" OFF) if(AKANTU_TESTS) include_directories( ${AKANTU_INCLUDE_DIRS} ${AKANTU_EXTERNAL_LIB_INCLUDE_DIR} ) find_package(GMSH REQUIRED) add_subdirectory(test) endif(AKANTU_TESTS) #=============================================================================== # Config gen for external packages #=============================================================================== export(TARGETS akantu FILE "${CMAKE_BINARY_DIR}/AkantuLibraryDepends.cmake") export(PACKAGE Akantu) configure_file(cmake/AkantuBuildTreeSettings.cmake.in "${CMAKE_BINARY_DIR}/AkantuBuildTreeSettings.cmake" @ONLY) # Create the AkantuConfig.cmake and AkantuConfigVersion files get_filename_component(CONF_REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}" ABSOLUTE) configure_file(cmake/AkantuConfig.cmake.in "${CMAKE_BINARY_DIR}/AkantuConfig.cmake" @ONLY) configure_file(cmake/AkantuConfigVersion.cmake.in "${CMAKE_BINARY_DIR}/AkantuConfigVersion.cmake" @ONLY) configure_file(cmake/AkantuUse.cmake "${CMAKE_BINARY_DIR}/AkantuUse.cmake" COPYONLY) # Install the export set for use with the install-tree install(EXPORT AkantuLibraryDepends DESTINATION lib/akantu COMPONENT dev) install(FILES ${CMAKE_BINARY_DIR}/AkantuConfig.cmake ${CMAKE_BINARY_DIR}/AkantuConfigVersion.cmake ${CMAKE_SOURCE_DIR}/cmake/AkantuUse.cmake DESTINATION lib/akantu COMPONENT dev) +install(FILES + ${CMAKE_SOURCE_DIR}/cmake/FindIOHelper.cmake + ${CMAKE_SOURCE_DIR}/cmake/FindMumps.cmake + ${CMAKE_SOURCE_DIR}/cmake/FindScotch.cmake + ${CMAKE_SOURCE_DIR}/cmake/FindGMSH.cmake + DESTINATION lib/akantu/cmake + COMPONENT dev) + #=============================================================================== # Package builder target module of CPack #=============================================================================== set(CPACK_GENERATOR "DEB;TGZ;TBZ2;STGZ") -set(CPACK_DEBIAN_PACKAGE_MAINTAINER "guillaume.anciaux@epfl.ch, nicolas.richart@epfl.ch") +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "guillaume.anciaux@epfl.ch, nicolas.richart@epfl.ch") #message(${CPACK_DEBIAN_PACKAGE_DEPENDS}) -if(CMAKE_SYSTEM_PROCESSOR MATCHES "i.86") - set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386" CACHE STRING "Architecture of debian package generation") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") +if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64" CACHE STRING "Architecture of debian package generation") else() - message(FAILURE "The architecture is unkown") + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386" CACHE STRING "Architecture of debian package generation") endif() #message("CPACK_DEBIAN_PACKAGE_ARCHITECTURE = ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}") set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Akantu library") set(CPACK_PACKAGE_VENDOR "LSMS") set(PACKAGE_FILE_NAME "akantu" CACHE STRING "Name of package to be generated") set(CPACK_PACKAGE_FILE_NAME "${PACKAGE_FILE_NAME}-${AKANTU_VERSION}-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE_FILE_NAME}-${AKANTU_VERSION}-src") set(CPACK_PACKAGE_VERSION "${AKANTU_VERSION}") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") -list(APPEND CPACK_SOURCE_IGNORE_FILES ${_exclude_source_file}) -list(APPEND CPACK_SOURCE_IGNORE_FILES ${_unactivated_package_file}) +list(APPEND CPACK_SOURCE_IGNORE_FILES ${AKANTU_EXCLUDE_SOURCE_FILE}) +list(APPEND CPACK_SOURCE_IGNORE_FILES ${AKANTU_UNACTIVATED_PACKAGE_FILE}) list(APPEND CPACK_SOURCE_IGNORE_FILES "/.*build.*/;/CVS/;/\\\\.svn/;/\\\\.bzr/;/\\\\.hg/;/\\\\.git/;\\\\.swp$;\\\\.#;/#;~") include(CPack) diff --git a/cmake/AkantuBuildTreeSettings.cmake.in b/cmake/AkantuBuildTreeSettings.cmake.in index 3c54c804d..c91764a06 100644 --- a/cmake/AkantuBuildTreeSettings.cmake.in +++ b/cmake/AkantuBuildTreeSettings.cmake.in @@ -1,3 +1,4 @@ set(AKANTU_INCLUDE_DIR "@AKANTU_INCLUDE_DIRS@" - ) \ No newline at end of file + ) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "@CMAKE_SOURCE_DIR@/cmake") \ No newline at end of file diff --git a/cmake/AkantuConfig.cmake.in b/cmake/AkantuConfig.cmake.in index 3bfec7d26..7972b42a6 100644 --- a/cmake/AkantuConfig.cmake.in +++ b/cmake/AkantuConfig.cmake.in @@ -1,64 +1,65 @@ #=============================================================================== # @file AkantuConfig.cmake.in # @author Nicolas Richart <nicolas.richart@epfl.ch> # @date Mon Nov 28 15:11:51 2011 # # @brief CMake file for the library # # @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 <http://www.gnu.org/licenses/>. # #=============================================================================== # Compute paths get_filename_component(AKANTU_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) set(AKANTU_USE_FILE "${AKANTU_CMAKE_DIR}/AkantuUse.cmake") include(${AKANTU_USE_FILE}) if(EXISTS "${AKANTU_CMAKE_DIR}/CMakeCache.txt") # In build tree include("${AKANTU_CMAKE_DIR}/AkantuBuildTreeSettings.cmake") else() set(AKANTU_INCLUDE_DIR "${AKANTU_CMAKE_DIR}/../../include/akantu") + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${AKANTU_CMAKE_DIR}/cmake") endif() include("${AKANTU_CMAKE_DIR}/AkantuLibraryDepends.cmake") # Dependancies set(AKANTU_USE_IOHELPER @AKANTU_IOHELPER@) set(AKANTU_USE_MPI @AKANTU_MPI@) set(AKANTU_USE_SCOTCH @AKANTU_SCOTCH@) set(AKANTU_USE_MUMPS @AKANTU_MUMPS@) set(AKANTU_USE_BLAS @AKANTU_BLAS@) set(AKANTU_HAS_PARTITIONER @AKANTU_PARTITIONER@) set(AKANTU_HAS_SOLVER @AKANTU_SOLVER@) # Features set(AKANTU_HAS_CONTACT @AKANTU_CONTACT@) set(AKANTU_HAS_HEAT_TRANSFER @AKANTU_HEAT_TRANSFER@) set(AKANTU_HAS_STRUCTURAL_MECHANICS @AKANTU_STRUCTURAL_MECHANICS@) set(AKANTU_BUILD_TYPE @CMAKE_BUILD_TYPE@) find_akantu_dependencies() set(AKANTU_LIBRARY akantu) list(APPEND AKANTU_LIBRARIES ${AKANTU_LIBRARY} ${AKANTU_EXTRA_LIBRARIES}) list(APPEND AKANTU_INCLUDE_DIR ${AKANTU_EXTRA_INCLUDE_DIR}) \ No newline at end of file diff --git a/cmake/AkantuMacros.cmake b/cmake/AkantuMacros.cmake index 170203555..29783b950 100644 --- a/cmake/AkantuMacros.cmake +++ b/cmake/AkantuMacros.cmake @@ -1,215 +1,221 @@ #=============================================================================== # @file AkantuMacros.cmake # @author Nicolas Richart <nicolas.richart@epfl.ch> # @date Wed Feb 9 10:59:42 2011 # # @brief Set of macros used by akantu cmake files # # @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 <http://www.gnu.org/licenses/>. # #=============================================================================== #=============================================================================== # macro to include optional packages macro(add_optional_package PACKAGE DESC DEFAULT) string(TOUPPER ${PACKAGE} _u_package) set(_option_name AKANTU_USE_${_u_package}) option(${_option_name} ${DESC} ${DEFAULT}) if(${_option_name}) if(${PACKAGE} MATCHES BLAS) enable_language(Fortran) endif() find_package(${PACKAGE} REQUIRED) if(${_u_package}_FOUND) - add_definitions(-DAKANTU_USE_${_u_package}) + list(APPEND AKANTU_DEFINITIONS AKANTU_USE_${_u_package}) if(DEFINED ${_u_package}_INCLUDE_DIR) list(APPEND AKANTU_EXTERNAL_LIB_INCLUDE_DIR ${${_u_package}_INCLUDE_DIR}) else() list(APPEND AKANTU_EXTERNAL_LIB_INCLUDE_DIR ${${_u_package}_INCLUDE_PATH}) endif() list(APPEND AKANTU_EXTERNAL_LIBRARIES ${${_u_package}_LIBRARIES}) set(AKANTU_${_u_package} ON) # MESSAGE("found ${_u_package} by setting AKANTU_${_u_package}" ) else(${_u_package}_FOUND) # MESSAGE("not found ${_u_package}" ) set(AKANTU_${_u_package} OFF) endif(${_u_package}_FOUND) endif(${_option_name}) endmacro() #=============================================================================== macro(check_for_isnan result) include(CheckFunctionExists) check_function_exists(std::isnan HAVE_STD_ISNAN) if(HAVE_STD_ISNAN) set(result "std::isnan(x)") else() check_function_exists(isnan HAVE_ISNAN) if(HAVE_ISNAN) set(result "(::isnan(x))") else() check_function_exists(_isnan HAVE_ISNAN_MATH_H) if(HAVE_ISNAN_MATH_H) set(result "(_isnan(x))") else() set(result (x == std::numeric_limits<Real>::quiet_NAN())) endif() endif() endif() endmacro() #=============================================================================== macro(copy_files target_depend) foreach(_file ${ARGN}) set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_file}) set(_source ${CMAKE_CURRENT_SOURCE_DIR}/${_file}) add_custom_command( OUTPUT ${_target} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_source} ${_target} DEPENDS ${_source} ) set(_target_name ${target_depend}_${_file}) add_custom_target(${_target_name} DEPENDS ${_target}) add_dependencies(${target_depend} ${_target_name}) endforeach() endmacro() #=============================================================================== # Package Management #=============================================================================== #=============================================================================== macro(add_all_packages package_dir) # message("PKG DIR : ${package_dir}") file(GLOB _akantu_package_list "${package_dir}/*.cmake") # message("PKG LIST : ${_akantu_package_list}") foreach(_pkg ${_akantu_package_list}) include(${_pkg}) get_filename_component(_basename ${_pkg} NAME) string(REGEX REPLACE "\\.cmake" "" _option_name ${_basename}) string(TOUPPER "${_option_name}" _option_name) list(APPEND AKANTU_PACKAGE_NAMES_LIST_ALL ${_option_name}) if (AKANTU_${_option_name}) list(APPEND AKANTU_PACKAGE_NAMES_LIST_ON ${_option_name}) else (AKANTU_${_option_name}) list(APPEND AKANTU_PACKAGE_NAMES_LIST_OFF ${_option_name}) - list(APPEND _unactivated_package_file ${_pkg}) + list(APPEND AKANTU_UNACTIVATED_PACKAGE_FILE ${_pkg}) endif() foreach(_file ${${_option_name}_FILES}) list(APPEND _release_all_file ${_file}) endforeach() endforeach() # message("ALL PKG : ${AKANTU_PACKAGE_NAMES_LIST_ALL}") # message("ON PKG : ${AKANTU_PACKAGE_NAMES_LIST_ON}") # message("ALL FILE LIST : ${_release_all_file}") #check if there are some file in the package list that are not on the current directory file(GLOB_RECURSE _all_files RELATIVE ${CMAKE_SOURCE_DIR}/src "*.cc" "*.hh") foreach(file ${all_files}) list(FIND RELEASE_ALL_FILE ${file} index) if (index EQUAL -1) MESSAGE("file ${file} is not registered in any package.") MESSAGE("Please append the file in one of the files within directory ${AKANTU_SOURCE_DIR}/packages") endif() endforeach() foreach(_file ${_release_all_file}) list(FIND _all_files ${_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 foreach(_pkg ${AKANTU_PACKAGE_NAMES_LIST_OFF}) foreach(_file ${${_pkg}_FILES}) # string(REGEX REPLACE "\\/" "\\\\\\\\/" __file ${_file}) # MESSAGE(${_file} " " ${__file}) # list(APPEND _exclude_source_file "/${__file}/") - list(APPEND _exclude_source_file ${_file}) + list(APPEND AKANTU_EXCLUDE_SOURCE_FILE ${_file}) endforeach() endforeach() #check dependencies foreach(_pkg ${AKANTU_PACKAGE_NAMES_LIST_ON}) # differentiate the file types - # message("DEPENDS PKG : ${_pkg}") - # message("DEPENDS LST : ${${_pkg}_DEPENDS}") - +# message("DEPENDS PKG : ${_pkg}") +# message("DEPENDS LST : ${${_pkg}_DEPENDS}") if (NOT "${${_pkg}_DEB_DEPEND}" STREQUAL "") set(deb_depend "${deb_depend}, ${${_pkg}_DEB_DEPEND}") endif() - + foreach(_dep ${${_pkg}_DEPENDS}) # message("DEPENDS DEP : ${_dep}") - if (NOT AKANTU_${dep}) + if (NOT AKANTU_${_dep}) message(FATAL_ERROR "Package ${_pkg} depends on package ${_dep}. You need to activate it to make it work") endif() endforeach() endforeach() set(CPACK_DEBIAN_PACKAGE_DEPENDS "${deb_depend}") endmacro() #=============================================================================== macro(generate_source_list_from_packages source_dir source_files headers_files include_dirs) set(deb_depend "libc6") - + # message("SRC DIR : ${source_dir}") foreach(_option_name ${AKANTU_PACKAGE_NAMES_LIST_ON}) # differentiate the file types foreach(_file ${${_option_name}_FILES}) if(${_file} MATCHES ".*inline.*\\.cc") list(APPEND ${_option_name}_inlines ${_file}) elseif(${_file} MATCHES ".*\\.hh") list(APPEND ${_option_name}_headers ${_file}) else() list(APPEND ${_option_name}_srcs ${_file}) endif() endforeach() # generates the include directory variable foreach(_file ${${_option_name}_headers}) get_filename_component(_absolute_name ${_file} ABSOLUTE) get_filename_component(_include_dir ${_absolute_name} PATH) list(APPEND ${_option_name}_include_dirs ${_include_dir}) list(REMOVE_DUPLICATES ${_option_name}_include_dirs) endforeach() # generate global lists for akantu to know what to build list(APPEND ${source_files} ${${_option_name}_srcs}) list(APPEND ${headers_files} ${${_option_name}_headers}) list(APPEND ${include_dirs} ${${_option_name}_include_dirs}) # message("PKG ${_option_name} SRCS : ${${_option_name}_srcs}") # message("PKG ${_option_name} HRDS : ${${_option_name}_headers}") # message("PKG ${_option_name} INCS : ${${_option_name}_include_dirs}") endforeach() # message("SRCS : ${${source_files}}") # message("HRDS : ${${headers_files}}") # message("INCS : ${${include_dirs}}") +endmacro() + +#=============================================================================== +macro(add_akantu_definitions) + foreach(_definition ${AKANTU_DEFINITIONS}) + add_definitions(-D${_definition}) + endforeach() endmacro() \ No newline at end of file diff --git a/cmake/AkantuUse.cmake b/cmake/AkantuUse.cmake index 5d0465ea6..1d975d5d9 100644 --- a/cmake/AkantuUse.cmake +++ b/cmake/AkantuUse.cmake @@ -1,53 +1,52 @@ #=============================================================================== # @file AkantuUse.cmake # @author Nicolas Richart <nicolas.richart@epfl.ch> # @date Mon Nov 28 15:11:51 2011 # # @brief CMake file for the library # # @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 <http://www.gnu.org/licenses/>. # #=============================================================================== macro(include_package_if_needed PACKAGE) string(TOUPPER ${PACKAGE} _package) if(AKANTU_USE_${_package}) if(${PACKAGE} MATCHES BLAS) enable_language(Fortran) endif() find_package(${PACKAGE} REQUIRED) if(${_package}_FOUND) if(DEFINED ${_package}_INCLUDE_DIR) list(APPEND AKANTU_EXTRA_INCLUDE_DIR ${${_package}_INCLUDE_DIR}) else() list(APPEND AKANTU_EXTRA_INCLUDE_DIR ${${_package}_INCLUDE_PATH}) endif() list(APPEND AKANTU_EXTRA_LIBRARIES ${${_package}_LIBRARIES}) endif() endif() endmacro() macro(find_akantu_dependencies) include_package_if_needed(MPI) include_package_if_needed(IOHelper) include_package_if_needed(Mumps) include_package_if_needed(Scotch) include_package_if_needed(BLAS) - message("AKANTU_EXTRA_LIBRARIES ${AKANTU_EXTRA_LIBRARIES}") endmacro() \ No newline at end of file diff --git a/cmake/FindIOHelper.cmake b/cmake/FindIOHelper.cmake index a21b34879..b510ca16c 100644 --- a/cmake/FindIOHelper.cmake +++ b/cmake/FindIOHelper.cmake @@ -1,57 +1,57 @@ #=============================================================================== # @file FindIOHelper.cmake # @author Nicolas Richart <nicolas.richart@epfl.ch> # @date Tue Aug 3 16:29:57 2010 # # @brief The find_package file for IOHelper # # @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 <http://www.gnu.org/licenses/>. # #=============================================================================== #=============================================================================== #set(IOHELPER_LIBRARY "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) find_library(IOHELPER_LIBRARY iohelper PATHS ${IOHELPER_DIR} PATH_SUFFIXES lib ) -find_path(IOHELPER_INCLUDE_PATH io_helper.h +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_PATH) +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_PATH) +find_package_handle_standard_args(IOHelper DEFAULT_MSG IOHELPER_LIBRARY IOHELPER_INCLUDE_DIR) diff --git a/cmake/FindMumps.cmake b/cmake/FindMumps.cmake index c6142bdc3..1450c3a49 100644 --- a/cmake/FindMumps.cmake +++ b/cmake/FindMumps.cmake @@ -1,102 +1,102 @@ #=============================================================================== # @file FindMumps.cmake # @author Nicolas Richart <nicolas.richart@epfl.ch> # @date Sun Dec 12 18:35:02 2010 # # @brief The find_package file for the Mumps solver # # @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 <http://www.gnu.org/licenses/>. # #=============================================================================== #=============================================================================== find_library(MUMPS_LIBRARY_DMUMPS NAMES dmumps_seq dmumps_ptscotch dmumps PATHS ${MUMPS_DIR} /usr PATH_SUFFIXES lib ) find_library(MUMPS_LIBRARY_COMMON NAMES mumps_seq mumps_common_ptscotch mumps_common PATHS ${MUMPS_DIR} PATH_SUFFIXES lib ) find_library(MUMPS_LIBRARY_PORD NAMES pord_seq pord_ptscotch pord PATHS ${MUMPS_DIR} PATH_SUFFIXES lib ) -find_path(MUMPS_INCLUDE_PATH dmumps_c.h +find_path(MUMPS_INCLUDE_DIR dmumps_c.h PATHS ${MUMPS_DIR} PATH_SUFFIXES include ) find_library(BLACS_LIBRARY_C NAME blacsC PATHS ${MUMPS_DIR} PATH_SUFFIXES lib) find_library(BLACS_LIBRARY_F77 NAME blacsF77 PATHS ${MUMPS_DIR} PATH_SUFFIXES lib) find_library(BLACS_LIBRARY NAME blacs PATHS ${MUMPS_DIR} PATH_SUFFIXES lib) find_library(SCALAPACK_LIBRARY NAME scalapack PATHS ${MUMPS_DIR} PATH_SUFFIXES lib) #enable_language(Fortran) #find_package(BLAS REQUIRED) #find_package(LAPACK REQUIRED) ##=============================================================================== mark_as_advanced(MUMPS_LIBRARY_COMMON) mark_as_advanced(MUMPS_LIBRARY_DMUMPS) mark_as_advanced(MUMPS_LIBRARY_PORD) -mark_as_advanced(MUMPS_INCLUDE_PATH) +mark_as_advanced(MUMPS_INCLUDE_DIR) mark_as_advanced(BLACS_LIBRARY_C) mark_as_advanced(BLACS_LIBRARY_F77) mark_as_advanced(BLACS_LIBRARY) mark_as_advanced(SCALAPACK_LIBRARY) set(MUMPS_LIBRARIES_ALL ${MUMPS_LIBRARY_DMUMPS} ${MUMPS_LIBRARY_COMMON} ${MUMPS_LIBRARY_PORD}) 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() 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.") endif(NOT Mumps_FOUND) #=============================================================================== include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Mumps DEFAULT_MSG - MUMPS_LIBRARIES MUMPS_INCLUDE_PATH) \ No newline at end of file + MUMPS_LIBRARIES MUMPS_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/FindScotch.cmake b/cmake/FindScotch.cmake index 982f41d26..68298cae9 100644 --- a/cmake/FindScotch.cmake +++ b/cmake/FindScotch.cmake @@ -1,90 +1,90 @@ #=============================================================================== # @file FindScotch.cmake # @author Nicolas Richart <nicolas.richart@epfl.ch> # @date Tue Aug 25 16:53:57 2010 # # @brief The find_package file for Scotch # # @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 <http://www.gnu.org/licenses/>. # #=============================================================================== #=============================================================================== #if(SCOTCH_DIR) # set(SCOTCH_LIBRARY "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) #endif(SCOTCH_DIR) find_library(SCOTCH_LIBRARY scotch PATHS ${SCOTCH_DIR} PATH_SUFFIXES src/libscotch lib ) find_library(SCOTCH_LIBRARY_ERR scotcherr PATHS ${SCOTCH_DIR} PATH_SUFFIXES src/libscotch lib ) find_library(SCOTCH_LIBRARY_ERREXIT scotcherrexit PATHS ${SCOTCH_DIR} PATH_SUFFIXES src/libscotch lib ) find_library(SCOTCH_LIBRARY_ESMUMPS ptesmumps PATHS ${SCOTCH_DIR} PATH_SUFFIXES src/libscotch lib ) find_path(SCOTCH_INCLUDE_DIR scotch.h PATHS ${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) #=============================================================================== include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Scotch DEFAULT_MSG SCOTCH_LIBRARY SCOTCH_LIBRARY_ERR SCOTCH_INCLUDE_DIR) #=============================================================================== if(NOT SCOTCH_FOUND) set(SCOTCH_DIR "" CACHE PATH "Location of Scotch library.") endif() if(SCOTCH_INCLUDE_DIR) - file(STRINGS ${SCOTCH_INCLUDE_PATH}/scotch.h SCOTCH_INCLUDE_CONTENT) + file(STRINGS ${SCOTCH_INCLUDE_DIR}/scotch.h SCOTCH_INCLUDE_CONTENT) string(REGEX MATCH "_cplusplus" _match ${SCOTCH_INCLUDE_CONTENT}) if(_match) add_definitions(-DAKANTU_SCOTCH_NO_EXTERN) endif() endif() diff --git a/doc/doxygen/CMakeLists.txt b/doc/doxygen/CMakeLists.txt index 64561e105..b41dc7227 100644 --- a/doc/doxygen/CMakeLists.txt +++ b/doc/doxygen/CMakeLists.txt @@ -1,52 +1,54 @@ #=============================================================================== # @file CMakeLists.txt # @author Nicolas Richart <nicolas.richart@epfl.ch> # @date Mon Sep 27 17:35:59 2010 # # @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 <http://www.gnu.org/licenses/>. # # @section DESCRIPTION # #=============================================================================== set(DOXYGEN_INPUT ${CMAKE_CURRENT_BINARY_DIR}/akantu.dox) set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/html) set(DOXYGEN_OUTPUT ${DOXYGEN_OUTPUT_DIR}/index.html) +string(REGEX REPLACE ":" " " AKANTU_DOXYGEN_DEFINTIONS "${AKANTU_DEFINITIONS}") + make_directory(${DOXYGEN_OUTPUT_DIR}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/akantu.dox.cmake ${CMAKE_CURRENT_BINARY_DIR}/akantu.dox) add_custom_command( OUTPUT ${DOXYGEN_OUTPUT} COMMAND ${CMAKE_COMMAND} -E echo "${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT}" COMMAND ${CMAKE_COMMAND} -E echo_append "Building akantu Documentation..." COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT} COMMAND ${CMAKE_COMMAND} -E echo "Done." DEPENDS ${DOXYGEN_INPUT} ) add_custom_target(akantu-doc ALL DEPENDS ${DOXYGEN_OUTPUT}) add_custom_target(akantu-doc-forced COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT} ) install(DIRECTORY ${DOXYGEN_OUTPUT_DIR} DESTINATION share/akantu-${akantu_VERSION}/doc) diff --git a/doc/doxygen/akantu.dox.cmake b/doc/doxygen/akantu.dox.cmake index 1f81cf122..51cd5d1f8 100644 --- a/doc/doxygen/akantu.dox.cmake +++ b/doc/doxygen/akantu.dox.cmake @@ -1,1568 +1,72 @@ -# Doxyfile 1.6.3 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project -# -# All text after a hash (#) is considered a comment and will be ignored -# The format is: -# TAG = value [value, ...] -# For lists items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (" ") - #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all -# text before the first occurrence of this tag. Doxygen uses libiconv (or the -# iconv built into libc) for the transcoding. See -# http://www.gnu.org/software/libiconv for the list of possible encodings. - DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded -# by quotes) that should identify the project. - -PROJECT_NAME = akantu - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. -# This could be handy for archiving the generated documentation or -# if some version control system is used. - +PROJECT_NAME = @CMAKE_PROJECT_NAME@ PROJECT_NUMBER = @AKANTU_VERSION@ - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) -# base path where the generated documentation will be put. -# If a relative path is entered, it will be relative to the location -# where doxygen was started. If left blank the current directory will be used. - OUTPUT_DIRECTORY = . - -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create -# 4096 sub-directories (in 2 levels) under the output directory of each output -# format and will distribute the generated files over these directories. -# Enabling this option can be useful when feeding doxygen a huge amount of -# source files, where putting all generated files in the same directory would -# otherwise cause performance problems for the file system. - -CREATE_SUBDIRS = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# The default language is English, other supported languages are: -# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, -# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, -# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English -# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, -# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, -# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. - OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in -# the file and class documentation (similar to JavaDoc). -# Set to NO to disable this. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend -# the brief description of a member or function before the detailed description. -# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator -# that is used to form the text in various listings. Each string -# in this list, if found as the leading text of the brief description, will be -# stripped from the text and the result after processing the whole list, is -# used as the annotated text. Otherwise, the brief description is used as-is. -# If left blank, the following values are used ("$name" is automatically -# replaced with the name of the entity): "The $name class" "The $name widget" -# "The $name file" "is" "provides" "specifies" "contains" -# "represents" "a" "an" "the" - -ABBREVIATE_BRIEF = - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# Doxygen will generate a detailed section even if there is only a brief -# description. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full -# path before files name in the file list and in the header files. If set -# to NO the shortest path that makes the file name unique will be used. - -FULL_PATH_NAMES = NO - -# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag -# can be used to strip a user-defined part of the path. Stripping is -# only done if one of the specified strings matches the left-hand part of -# the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the -# path to strip. - -STRIP_FROM_PATH = - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of -# the path mentioned in the documentation of a class, which tells -# the reader which header file to include in order to use a class. -# If left blank only the name of the header file containing the class -# definition is used. Otherwise one should specify the include paths that -# are normally passed to the compiler using the -I flag. - -STRIP_FROM_INC_PATH = - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful is your file systems -# doesn't support long names like on DOS, Mac, or CD-ROM. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen -# will interpret the first line (until the first dot) of a JavaDoc-style -# comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like regular Qt-style comments -# (thus requiring an explicit @brief command for a brief description.) - -JAVADOC_AUTOBRIEF = NO - -# If the QT_AUTOBRIEF tag is set to YES then Doxygen will -# interpret the first line (until the first dot) of a Qt-style -# comment as the brief description. If set to NO, the comments -# will behave just like regular Qt-style comments (thus requiring -# an explicit \brief command for a brief description.) - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen -# treat a multi-line C++ special comment block (i.e. a block of //! or /// -# comments) as a brief description. This used to be the default behaviour. -# The new default is to treat a multi-line C++ comment block as a detailed -# description. Set this tag to YES if you prefer the old behaviour instead. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it -# re-implements. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce -# a new page for each member. If set to NO, the documentation of a member will -# be part of the file/class/namespace that contains it. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. -# Doxygen uses this value to replace tabs by spaces in code fragments. - -TAB_SIZE = 8 - -# This tag can be used to specify a number of aliases that acts -# as commands in the documentation. An alias has the form "name=value". -# For example adding "sideeffect=\par Side Effects:\n" will allow you to -# put the command \sideeffect (or @sideeffect) in the documentation, which -# will result in a user-defined paragraph with heading "Side Effects:". -# You can put \n's in the value part of an alias to insert newlines. - -ALIASES = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C -# sources only. Doxygen will then generate output that is more tailored for C. -# For instance, some of the names that are used will be different. The list -# of all members will be omitted, etc. - -OPTIMIZE_OUTPUT_FOR_C = NO - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java -# sources only. Doxygen will then generate output that is more tailored for -# Java. For instance, namespaces will be presented as packages, qualified -# scopes will look different, etc. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources only. Doxygen will then generate output that is more tailored for -# Fortran. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for -# VHDL. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it parses. -# With this tag you can assign which parser to use for a given extension. -# Doxygen has a built-in mapping, but you can override or extend it using this tag. -# The format is ext=language, where ext is a file extension, and language is one of -# the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP, -# Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat -# .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran), -# use: inc=Fortran f=C. Note that for custom extensions you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should -# set this tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. -# func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. -# Doxygen will parse them like normal C++ but will assume all classes use public -# instead of private inheritance when no explicit protection keyword is present. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate getter -# and setter methods for a property. Setting this option to YES (the default) -# will make doxygen to replace the get and set methods by a property in the -# documentation. This will only work if the methods are indeed getting or -# setting a simple type. If this is not the case, or you want to show the -# methods anyway, you should set this option to NO. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. - -DISTRIBUTE_GROUP_DOC = NO - -# Set the SUBGROUPING tag to YES (the default) to allow class member groups of -# the same type (for instance a group of public functions) to be put as a -# subgroup of that type (e.g. under the Public Functions section). Set it to -# NO to prevent subgrouping. Alternatively, this can be done per class using -# the \nosubgrouping command. - -SUBGROUPING = YES - -# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum -# is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically -# be useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. - -TYPEDEF_HIDES_STRUCT = NO - -# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to -# determine which symbols to keep in memory and which to flush to disk. -# When the cache is full, less often used symbols will be written to disk. -# For small to medium size projects (<1000 input files) the default value is -# probably good enough. For larger projects a too small cache size can cause -# doxygen to be busy swapping symbols to and from disk most of the time -# causing a significant performance penality. -# If the system has enough physical memory increasing the cache will improve the -# performance by keeping more symbols in memory. Note that the value works on -# a logarithmic scale so increasing the size by one will rougly double the -# memory usage. The cache size is given by this formula: -# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, -# corresponding to a cache size of 2^16 = 65536 symbols - -SYMBOL_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES - -EXTRACT_ALL = NO - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. - -EXTRACT_PRIVATE = YES - -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. - -EXTRACT_STATIC = YES - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base -# name of the file that contains the anonymous namespace. By default -# anonymous namespace are hidden. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the -# documentation. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any -# documentation blocks found inside the body of a function. -# If set to NO (the default) these blocks will be appended to the -# function's detailed documentation block. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation -# that is typed after a \internal command is included. If the tag is set -# to NO (the default) then the documentation will be excluded. -# Set it to YES to include the internal documentation. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate -# file names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. - -CASE_SENSE_NAMES = YES - -# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen -# will show members with their full class and namespace scopes in the -# documentation. If set to YES the scope will be hidden. - -HIDE_SCOPE_NAMES = NO - -# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put a list of the files that are included by a file in the documentation -# of that file. - -SHOW_INCLUDE_FILES = YES - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen -# will list include files with double quotes in the documentation -# rather than with sharp brackets. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] -# is inserted in the documentation for inline members. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen -# will sort the (detailed) documentation of file and class members -# alphabetically by member name. If set to NO the members will appear in -# declaration order. - -SORT_MEMBER_DOCS = YES - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the -# brief documentation of file, namespace and class members alphabetically -# by member name. If set to NO (the default) the members will appear in -# declaration order. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the (brief and detailed) documentation of class members so that constructors and destructors are listed first. If set to NO (the default) the constructors will appear in the respective orders defined by SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. - -SORT_MEMBERS_CTORS_1ST = NO - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the -# hierarchy of group names into alphabetical order. If set to NO (the default) -# the group names will appear in their defined order. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be -# sorted by fully-qualified names, including namespaces. If set to -# NO (the default), the class list will be sorted only by class name, -# not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the -# alphabetical list. - -SORT_BY_SCOPE_NAME = NO - -# The GENERATE_TODOLIST tag can be used to enable (YES) or -# disable (NO) the todo list. This list is created by putting \todo -# commands in the documentation. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable (YES) or -# disable (NO) the test list. This list is created by putting \test -# commands in the documentation. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable (YES) or -# disable (NO) the bug list. This list is created by putting \bug -# commands in the documentation. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or -# disable (NO) the deprecated list. This list is created by putting -# \deprecated commands in the documentation. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional -# documentation sections, marked by \if sectionname ... \endif. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or define consists of for it to appear in -# the documentation. If the initializer consists of more lines than specified -# here it will be hidden. Use a value of 0 to hide initializers completely. -# The appearance of the initializer of individual variables and defines in the -# documentation can be controlled using \showinitializer or \hideinitializer -# command in the documentation regardless of this setting. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated -# at the bottom of the documentation of classes and structs. If set to YES the -# list will mention the files that were used to generate the documentation. - -SHOW_USED_FILES = YES - -# If the sources in your project are distributed over multiple directories -# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy -# in the documentation. The default is NO. - -SHOW_DIRECTORIES = NO - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. -# This will remove the Files entry from the Quick Index and from the -# Folder Tree View (if specified). The default is YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the -# Namespaces page. -# This will remove the Namespaces entry from the Quick Index -# and from the Folder Tree View (if specified). The default is YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command <command> <input-file>, where <command> is the value of -# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file -# provided by doxygen. Whatever the program writes to standard output -# is used as the file version. See the manual for examples. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by -# doxygen. The layout file controls the global structure of the generated output files -# in an output format independent way. The create the layout file that represents -# doxygen's defaults, run doxygen with the -l option. You can optionally specify a -# file name after the option, if omitted DoxygenLayout.xml will be used as the name -# of the layout file. - -LAYOUT_FILE = +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = @CMAKE_SOURCE_DIR@ +STRIP_FROM_INC_PATH = @CMAKE_SOURCE_DIR@ +TAB_SIZE = 4 +BUILTIN_STL_SUPPORT = YES #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- -# The QUIET tag can be used to turn on/off the messages that are generated -# by doxygen. Possible values are YES and NO. If left blank NO is used. - QUIET = @DOXYGEN_QUIET@ - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated by doxygen. Possible values are YES and NO. If left blank -# NO is used. - WARNINGS = @DOXYGEN_WARNINGS@ - -# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings -# for undocumented members. If EXTRACT_ALL is set to YES then this flag will -# automatically be disabled. - WARN_IF_UNDOCUMENTED = @DOXYGEN_WARNINGS@ - -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that -# don't exist or using markup commands wrongly. - WARN_IF_DOC_ERROR = @DOXYGEN_WARNINGS@ -# This WARN_NO_PARAMDOC option can be abled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of -# documentation. - -WARN_NO_PARAMDOC = NO - -# The WARN_FORMAT tag determines the format of the warning messages that -# doxygen can produce. The string should contain the $file, $line, and $text -# tags, which will be replaced by the file and line number from which the -# warning originated and the warning text. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could -# be obtained via FILE_VERSION_FILTER) - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning -# and error messages should be written. If left blank the output is written -# to stderr. - -WARN_LOGFILE = - #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -# The INPUT tag can be used to specify the files and/or directories that contain -# documented source files. You may enter file names like "myfile.cpp" or -# directories like "/usr/src/myproject". Separate the files or directories -# with spaces. - -INPUT = @CMAKE_SOURCE_DIR@ - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is -# also the default input encoding. Doxygen uses libiconv (or the iconv built -# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for -# the list of possible encodings. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx -# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 - -FILE_PATTERNS = - -# The RECURSIVE tag can be used to turn specify whether or not subdirectories -# should be searched for input files as well. Possible values are YES and NO. -# If left blank NO is used. - -RECURSIVE = YES - -# The EXCLUDE tag can be used to specify files and/or directories that should -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. - -EXCLUDE = @CMAKE_SOURCE_DIR@/doc - -# The EXCLUDE_SYMLINKS tag can be used select whether or not files or -# directories that are symbolic links (a Unix filesystem feature) are excluded -# from the input. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. Note that the wildcards are matched -# against the file with absolute path, so to exclude all test directories -# for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or -# directories that contain example code fragments that are included (see -# the \include command). - +INPUT = @CMAKE_SOURCE_DIR@/src EXAMPLE_PATH = @CMAKE_SOURCE_DIR@/test -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank all files are included. - -EXAMPLE_PATTERNS = - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude -# commands irrespective of the value of the RECURSIVE tag. -# Possible values are YES and NO. If left blank NO is used. - -EXAMPLE_RECURSIVE = YES - -# The IMAGE_PATH tag can be used to specify one or more files or -# directories that contain image that are included in the documentation (see -# the \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command <filter> <input-file>, where <filter> -# is the value of the INPUT_FILTER tag, and <input-file> is the name of an -# input file. Doxygen will then use the output that the filter program writes -# to standard output. -# If FILTER_PATTERNS is specified, this tag will be -# ignored. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. -# Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. -# The filters are a list of the form: -# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER -# is applied to all files. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will be used to filter the input files when producing source -# files to browse (i.e. when SOURCE_BROWSER is set to YES). - -FILTER_SOURCE_FILES = NO - #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. -# Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. - SOURCE_BROWSER = YES - -# Setting the INLINE_SOURCES tag to YES will include the body -# of functions and classes directly in the documentation. - INLINE_SOURCES = NO -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code -# fragments. Normal C and C++ comments will always remain visible. - -STRIP_CODE_COMMENTS = NO - -# If the REFERENCED_BY_RELATION tag is set to YES -# then for each documented function all documented -# functions referencing it will be listed. - -REFERENCED_BY_RELATION = NO - -# If the REFERENCES_RELATION tag is set to YES -# then for each documented function all documented entities -# called/used by that function will be listed. - -REFERENCES_RELATION = NO - -# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) -# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from -# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will -# link to the source code. -# Otherwise they will link to the documentation. - -REFERENCES_LINK_SOURCE = YES - -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You -# will need version 4.8.6 or higher. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for -# which an include is specified. Set to NO to disable this. - -VERBATIM_HEADERS = YES - -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index -# of all compounds will be generated. Enable this if the project -# contains a lot of classes, structs, unions or interfaces. - -ALPHABETICAL_INDEX = YES - -# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then -# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns -# in which this list will be split (can be a number in the range [1..20]) - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all -# classes will be put under the same header in the alphabetical index. -# The IGNORE_PREFIX tag can be used to specify one or more prefixes that -# should be ignored while generating the index headers. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES (the default) Doxygen will -# generate HTML output. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `html' will be used as the default path. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank -# doxygen will generate files with .html extension. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a personal HTML header for -# each generated HTML page. If it is left blank doxygen will generate a -# standard header. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a personal HTML footer for -# each generated HTML page. If it is left blank doxygen will generate a -# standard footer. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading -# style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# stylesheet in the HTML output directory as well, or it will be erased! - -HTML_STYLESHEET = - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting -# this to NO can help when comparing the output of multiple runs. - -HTML_TIMESTAMP = YES - -# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, -# files or namespaces will be aligned in HTML using tables. If set to -# NO a bullet list will be used. - -HTML_ALIGN_MEMBERS = YES - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. For this to work a browser that supports -# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox -# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). - -HTML_DYNAMIC_SECTIONS = YES - -# If the GENERATE_DOCSET tag is set to YES, additional index files -# will be generated that can be used as input for Apple's Xcode 3 -# integrated development environment, introduced with OSX 10.5 (Leopard). -# To create a documentation set, doxygen will generate a Makefile in the -# HTML output directory. Running make will produce the docset in that -# directory and running "make install" will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find -# it at startup. -# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information. - -GENERATE_DOCSET = NO - -# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the -# feed. A documentation feed provides an umbrella under which multiple -# documentation sets from a single provider (such as a company or product suite) -# can be grouped. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that -# should uniquely identify the documentation set bundle. This should be a -# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen -# will append .docset to the name. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# If the GENERATE_HTMLHELP tag is set to YES, additional index files -# will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) -# of the generated HTML documentation. - -GENERATE_HTMLHELP = NO - -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be -# written to the html output directory. - -CHM_FILE = - -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run -# the HTML help compiler on the generated index.hhp. - -HHC_LOCATION = - -# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag -# controls if a separate .chi index file is generated (YES) or that -# it should be included in the master .chm file (NO). - -GENERATE_CHI = NO - -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING -# is used to encode HtmlHelp index (hhk), content (hhc) and project file -# content. - -CHM_INDEX_ENCODING = - -# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag -# controls whether a binary table of contents is generated (YES) or a -# normal table of contents (NO) in the .chm file. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members -# to the contents of the HTML help documentation and to the tree view. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER -# are set, an additional index file will be generated that can be used as input for -# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated -# HTML documentation. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can -# be used to specify the file name of the resulting .qch file. -# The path specified is relative to the HTML output folder. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#namespace - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#virtual-folders - -QHP_VIRTUAL_FOLDER = doc - -# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add. -# For more information please see -# http://doc.trolltech.com/qthelpproject.html#custom-filters - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see -# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">Qt Help Project / Custom Filters</a>. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's -# filter section matches. -# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">Qt Help Project / Filter Attributes</a>. - -QHP_SECT_FILTER_ATTRS = - -# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can -# be used to specify the location of Qt's qhelpgenerator. -# If non-empty doxygen will try to run qhelpgenerator on the generated -# .qhp file. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files -# will be generated, which together with the HTML files, form an Eclipse help -# plugin. To install this plugin and make it available under the help contents -# menu in Eclipse, the contents of the directory containing the HTML and XML -# files needs to be copied into the plugins directory of eclipse. The name of -# the directory within the plugins directory should be the same as -# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before the help appears. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have -# this name. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# The DISABLE_INDEX tag can be used to turn on/off the condensed index at -# top of each HTML page. The value NO (the default) enables the index and -# the value YES disables it. - -DISABLE_INDEX = NO - -# This tag can be used to set the number of enum values (range [1..20]) -# that doxygen will group on one line in the generated HTML documentation. - -ENUM_VALUES_PER_LINE = 4 - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. -# If the tag value is set to YES, a side panel will be generated -# containing a tree-like index structure (just like the one that -# is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). -# Windows users are probably better off using the HTML help feature. - -GENERATE_TREEVIEW = NO - -# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, -# and Class Hierarchy pages using a tree view instead of an ordered list. - -USE_INLINE_TREES = NO - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be -# used to set the initial width (in pixels) of the frame in which the tree -# is shown. - -TREEVIEW_WIDTH = 250 - -# Use this tag to change the font size of Latex formulas included -# as images in the HTML documentation. The default is 10. Note that -# when you change the font size after a successful doxygen run you need -# to manually remove any form_*.png images from the HTML output directory -# to force them to be regenerated. - -FORMULA_FONTSIZE = 10 - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box for the HTML output. The underlying search engine uses javascript -# and DHTML and should work on any modern browser. Note that when using HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) there is already a search function so this one should -# typically be disabled. For large projects the javascript based search engine -# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. - -SEARCHENGINE = YES - -# When the SERVER_BASED_SEARCH tag is enabled the search engine will be implemented using a PHP enabled web server instead of at the web client using Javascript. Doxygen will generate the search PHP script and index -# file to put on the web server. The advantage of the server based approach is that it scales better to large projects and allows full text search. The disadvances is that it is more difficult to setup -# and does not have live searching capabilities. - -SERVER_BASED_SEARCH = NO - -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- - -# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will -# generate Latex output. - -GENERATE_LATEX = NO - -# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `latex' will be used as the default path. - -LATEX_OUTPUT = latex - -# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be -# invoked. If left blank `latex' will be used as the default command name. -# Note that when enabling USE_PDFLATEX this option is only used for -# generating bitmaps for formulas in the HTML output, but not in the -# Makefile that is written to the output directory. - -LATEX_CMD_NAME = latex - -# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to -# generate index for LaTeX. If left blank `makeindex' will be used as the -# default command name. - -MAKEINDEX_CMD_NAME = makeindex - -# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact -# LaTeX documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_LATEX = NO - -# The PAPER_TYPE tag can be used to set the paper type that is used -# by the printer. Possible values are: a4, a4wide, letter, legal and -# executive. If left blank a4wide will be used. - -PAPER_TYPE = a4wide - -# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX -# packages that should be included in the LaTeX output. - -EXTRA_PACKAGES = - -# The LATEX_HEADER tag can be used to specify a personal LaTeX header for -# the generated latex document. The header should contain everything until -# the first chapter. If it is left blank doxygen will generate a -# standard header. Notice: only use this tag if you know what you are doing! - -LATEX_HEADER = - -# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated -# is prepared for conversion to pdf (using ps2pdf). The pdf file will -# contain links (just like the HTML output) instead of page references -# This makes the output suitable for online browsing using a pdf viewer. - -PDF_HYPERLINKS = YES - -# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of -# plain latex in the generated Makefile. Set this option to YES to get a -# higher quality PDF documentation. - -USE_PDFLATEX = YES - -# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. -# command to the generated LaTeX files. This will instruct LaTeX to keep -# running if errors occur, instead of asking the user for help. -# This option is also used when generating formulas in HTML. - -LATEX_BATCHMODE = NO - -# If LATEX_HIDE_INDICES is set to YES then doxygen will not -# include the index chapters (such as File Index, Compound Index, etc.) -# in the output. - -LATEX_HIDE_INDICES = NO - -# If LATEX_SOURCE_CODE is set to YES then doxygen will include source code with syntax highlighting in the LaTeX output. Note that which sources are shown also depends on other settings such as SOURCE_BROWSER. - -LATEX_SOURCE_CODE = NO - -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- - -# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output -# The RTF output is optimized for Word 97 and may not look very pretty with -# other RTF readers or editors. - -GENERATE_RTF = NO - -# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `rtf' will be used as the default path. - -RTF_OUTPUT = rtf - -# If the COMPACT_RTF tag is set to YES Doxygen generates more compact -# RTF documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_RTF = NO - -# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated -# will contain hyperlink fields. The RTF file will -# contain links (just like the HTML output) instead of page references. -# This makes the output suitable for online browsing using WORD or other -# programs which support those fields. -# Note: wordpad (write) and others do not support links. - -RTF_HYPERLINKS = NO - -# Load stylesheet definitions from file. Syntax is similar to doxygen's -# config file, i.e. a series of assignments. You only have to provide -# replacements, missing definitions are set to their default value. - -RTF_STYLESHEET_FILE = - -# Set optional variables used in the generation of an rtf document. -# Syntax is similar to doxygen's config file. - -RTF_EXTENSIONS_FILE = - -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- - -# If the GENERATE_MAN tag is set to YES (the default) Doxygen will -# generate man pages - -GENERATE_MAN = NO - -# The MAN_OUTPUT tag is used to specify where the man pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `man' will be used as the default path. - -MAN_OUTPUT = man - -# The MAN_EXTENSION tag determines the extension that is added to -# the generated man pages (default is the subroutine's section .3) - -MAN_EXTENSION = .3 - -# If the MAN_LINKS tag is set to YES and Doxygen generates man output, -# then it will generate one additional man file for each entity -# documented in the real man page(s). These additional files -# only source the real man page, but without them the man command -# would be unable to find the correct page. The default is NO. - -MAN_LINKS = NO - -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- - -# If the GENERATE_XML tag is set to YES Doxygen will -# generate an XML file that captures the structure of -# the code including all documentation. - -GENERATE_XML = NO - -# The XML_OUTPUT tag is used to specify where the XML pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `xml' will be used as the default path. - -XML_OUTPUT = xml - -# The XML_SCHEMA tag can be used to specify an XML schema, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_SCHEMA = - -# The XML_DTD tag can be used to specify an XML DTD, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_DTD = - -# If the XML_PROGRAMLISTING tag is set to YES Doxygen will -# dump the program listings (including syntax highlighting -# and cross-referencing information) to the XML output. Note that -# enabling this will significantly increase the size of the XML output. - -XML_PROGRAMLISTING = YES - -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- - -# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will -# generate an AutoGen Definitions (see autogen.sf.net) file -# that captures the structure of the code including all -# documentation. Note that this feature is still experimental -# and incomplete at the moment. - -GENERATE_AUTOGEN_DEF = NO - -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- - -# If the GENERATE_PERLMOD tag is set to YES Doxygen will -# generate a Perl module file that captures the structure of -# the code including all documentation. Note that this -# feature is still experimental and incomplete at the -# moment. - -GENERATE_PERLMOD = NO - -# If the PERLMOD_LATEX tag is set to YES Doxygen will generate -# the necessary Makefile rules, Perl scripts and LaTeX code to be able -# to generate PDF and DVI output from the Perl module output. - -PERLMOD_LATEX = NO - -# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be -# nicely formatted so it can be parsed by a human reader. -# This is useful -# if you want to understand what is going on. -# On the other hand, if this -# tag is set to NO the size of the Perl module output will be much smaller -# and Perl will parse it just the same. - -PERLMOD_PRETTY = YES - -# The names of the make variables in the generated doxyrules.make file -# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. -# This is useful so different doxyrules.make files included by the same -# Makefile don't overwrite each other's variables. - -PERLMOD_MAKEVAR_PREFIX = - #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- -# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will -# evaluate all C-preprocessor directives found in the sources and include -# files. - ENABLE_PREPROCESSING = YES - -# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro -# names in the source code. If set to NO (the default) only conditional -# compilation will be performed. Macro expansion can be done in a controlled -# way by setting EXPAND_ONLY_PREDEF to YES. - MACRO_EXPANSION = YES - -# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES -# then the macro expansion is limited to the macros specified with the -# PREDEFINED and EXPAND_AS_DEFINED tags. - -EXPAND_ONLY_PREDEF = YES - -# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files -# in the INCLUDE_PATH (see below) will be search if a #include is found. - +EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES - -# The INCLUDE_PATH tag can be used to specify one or more directories that -# contain include files that are not input files but should be processed by -# the preprocessor. - -INCLUDE_PATH = @CMAKE_SOURCE_DIR@/common \ - @CMAKE_SOURCE_DIR@/synchronizer \ - @CMAKE_SOURCE_DIR@/fem \ - @CMAKE_SOURCE_DIR@/fem/element_classes \ - @CMAKE_SOURCE_DIR@/mesh_utils \ - @CMAKE_SOURCE_DIR@/mesh_utils/mesh_io \ - @CMAKE_SOURCE_DIR@/mesh_utils/mesh_partition \ - @CMAKE_SOURCE_DIR@/model \ - @CMAKE_SOURCE_DIR@/model/integration_scheme \ - @CMAKE_SOURCE_DIR@/model/solid_mechanics \ - @CMAKE_SOURCE_DIR@/model/solid_mechanics/materials \ - @CMAKE_SOURCE_DIR@/model/solid_mechanics/contact - - -# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard -# patterns (like *.h and *.hpp) to filter out the header-files in the -# directories. If left blank, the patterns specified with FILE_PATTERNS will -# be used. - -INCLUDE_FILE_PATTERNS = - -# The PREDEFINED tag can be used to specify one or more macro names that -# are defined before the preprocessor is started (similar to the -D option of -# gcc). The argument of the tag is a list of macros of the form: name -# or name=definition (no spaces). If the definition and the = are -# omitted =1 is assumed. To prevent a macro definition from being -# undefined via #undef or recursively expanded use the := operator -# instead of the = operator. - -PREDEFINED = - -# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then -# this tag can be used to specify a list of macro names that should be expanded. -# The macro definition that is found in the sources will be used. -# Use the PREDEFINED tag if you want to use a different macro definition. - +INCLUDE_PATH = @CMAKE_SOURCE_DIR@/src/common \ + @CMAKE_SOURCE_DIR@/src/synchronizer \ + @CMAKE_SOURCE_DIR@/src/solver \ + @CMAKE_SOURCE_DIR@/src/fem \ + @CMAKE_SOURCE_DIR@/src/fem/element_classes \ + @CMAKE_SOURCE_DIR@/src/mesh_utils \ + @CMAKE_SOURCE_DIR@/src/mesh_utils/mesh_io \ + @CMAKE_SOURCE_DIR@/src/mesh_utils/mesh_partition \ + @CMAKE_SOURCE_DIR@/src/model \ + @CMAKE_SOURCE_DIR@/src/model/integration_scheme \ + @CMAKE_SOURCE_DIR@/src/model/solid_mechanics \ + @CMAKE_SOURCE_DIR@/src/model/solid_mechanics/materials \ + @CMAKE_SOURCE_DIR@/src/model/solid_mechanics/contact + + + +INCLUDE_FILE_PATTERNS = *.hh +PREDEFINED = @AKANTU_DOXYGEN_DEFINTIONS@ EXPAND_AS_DEFINED = __BEGIN_AKANTU__ \ __END_AKANTU__ \ AKANTU_GET_MACRO \ AKANTU_SET_MACRO \ AKANTU_GET_MACRO_NOT_CONST \ AKANTU_GET_MACRO_BY_ELEMENT_TYPE -# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then -# doxygen's preprocessor will remove all function-like macros that are alone -# on a line, have an all uppercase name, and do not end with a semicolon. Such -# function macros are typically used for boiler-plate code, and will confuse -# the parser if not removed. - -SKIP_FUNCTION_MACROS = NO - -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- - -# The TAGFILES option can be used to specify one or more tagfiles. -# Optionally an initial location of the external documentation -# can be added for each tagfile. The format of a tag file without -# this location is as follows: -# -# TAGFILES = file1 file2 ... -# Adding location for the tag files is done as follows: -# -# TAGFILES = file1=loc1 "file2 = loc2" ... -# where "loc1" and "loc2" can be relative or absolute paths or -# URLs. If a location is present for each tag, the installdox tool -# does not have to be run to correct the links. -# Note that each tag file must have a unique name -# (where the name does NOT include the path) -# If a tag file is not located in the directory in which doxygen -# is run, you must also specify the path to the tagfile here. - -TAGFILES = - -# When a file name is specified after GENERATE_TAGFILE, doxygen will create -# a tag file that is based on the input files it reads. - -GENERATE_TAGFILE = - -# If the ALLEXTERNALS tag is set to YES all external classes will be listed -# in the class index. If set to NO only the inherited external classes -# will be listed. - -ALLEXTERNALS = NO - -# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed -# in the modules index. If set to NO, only the current project's groups will -# be listed. - -EXTERNAL_GROUPS = YES - -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of `which perl'). - -PERL_PATH = /usr/bin/perl - -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- - -# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will -# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base -# or super classes. Setting the tag to NO turns the diagrams off. Note that -# this option is superseded by the HAVE_DOT option below. This is only a -# fallback. It is recommended to install and use dot, since it yields more -# powerful graphs. - -CLASS_DIAGRAMS = YES - -# You can define message sequence charts within doxygen comments using the \msc -# command. Doxygen will then run the mscgen tool (see -# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the -# documentation. The MSCGEN_PATH tag allows you to specify the directory where -# the mscgen tool resides. If left empty the tool is assumed to be found in the -# default search path. - -MSCGEN_PATH = - -# If set to YES, the inheritance and collaboration graphs will hide -# inheritance and usage relations if the target is undocumented -# or is not a class. - -HIDE_UNDOC_RELATIONS = YES - -# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is -# available from the path. This tool is part of Graphviz, a graph visualization -# toolkit from AT&T and Lucent Bell Labs. The other options in this section -# have no effect if this option is set to NO (the default) - -HAVE_DOT = YES - -# By default doxygen will write a font called FreeSans.ttf to the output -# directory and reference it in all dot files that doxygen generates. This -# font does not include all possible unicode characters however, so when you need -# these (or just want a differently looking font) you can specify the font name -# using DOT_FONTNAME. You need need to make sure dot is able to find the font, -# which can be done by putting it in a standard location or by setting the -# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory -# containing the font. - -DOT_FONTNAME = FreeSans - -# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. -# The default size is 10pt. - -DOT_FONTSIZE = 10 - -# By default doxygen will tell dot to use the output directory to look for the -# FreeSans.ttf font (which doxygen will put there itself). If you specify a -# different font using DOT_FONTNAME you can set the path where dot -# can find it using this tag. - -DOT_FONTPATH = - -# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect inheritance relations. Setting this tag to YES will force the -# the CLASS_DIAGRAMS tag to NO. - -CLASS_GRAPH = YES - -# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect implementation dependencies (inheritance, containment, and -# class references variables) of the class with other documented classes. - -COLLABORATION_GRAPH = YES - -# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for groups, showing the direct groups dependencies - -GROUP_GRAPHS = YES - -# If the UML_LOOK tag is set to YES doxygen will generate inheritance and -# collaboration diagrams in a style similar to the OMG's Unified Modeling -# Language. - -UML_LOOK = NO - -# If set to YES, the inheritance and collaboration graphs will show the -# relations between templates and their instances. - -TEMPLATE_RELATIONS = YES - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT -# tags are set to YES then doxygen will generate a graph for each documented -# file showing the direct and indirect include dependencies of the file with -# other documented files. - -INCLUDE_GRAPH = YES - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and -# HAVE_DOT tags are set to YES then doxygen will generate a graph for each -# documented header file showing the documented files that directly or -# indirectly include this file. - -INCLUDED_BY_GRAPH = YES - -# If the CALL_GRAPH and HAVE_DOT options are set to YES then -# doxygen will generate a call dependency graph for every global function -# or class method. Note that enabling this option will significantly increase -# the time of a run. So in most cases it will be better to enable call graphs -# for selected functions only using the \callgraph command. - -CALL_GRAPH = NO - -# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then -# doxygen will generate a caller dependency graph for every global function -# or class method. Note that enabling this option will significantly increase -# the time of a run. So in most cases it will be better to enable caller -# graphs for selected functions only using the \callergraph command. - -CALLER_GRAPH = NO - -# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen -# will graphical hierarchy of all classes instead of a textual one. - -GRAPHICAL_HIERARCHY = YES - -# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES -# then doxygen will show the dependencies a directory has on other directories -# in a graphical way. The dependency relations are determined by the #include -# relations between the files in the directories. - -DIRECTORY_GRAPH = YES - -# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. Possible values are png, jpg, or gif -# If left blank png will be used. - -DOT_IMAGE_FORMAT = png - -# The tag DOT_PATH can be used to specify the path where the dot tool can be -# found. If left blank, it is assumed the dot tool can be found in the path. - -DOT_PATH = - -# The DOTFILE_DIRS tag can be used to specify one or more directories that -# contain dot files that are included in the documentation (see the -# \dotfile command). - -DOTFILE_DIRS = - -# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of -# nodes that will be shown in the graph. If the number of nodes in a graph -# becomes larger than this value, doxygen will truncate the graph, which is -# visualized by representing a node as a red box. Note that doxygen if the -# number of direct children of the root node in a graph is already larger than -# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note -# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. - -DOT_GRAPH_MAX_NODES = 50 - -# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the -# graphs generated by dot. A depth value of 3 means that only nodes reachable -# from the root by following a path via at most 3 edges will be shown. Nodes -# that lay further from the root node will be omitted. Note that setting this -# option to 1 or 2 may greatly reduce the computation time needed for large -# code bases. Also note that the size of a graph can be further restricted by -# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. - -MAX_DOT_GRAPH_DEPTH = 0 - -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, because dot on Windows does not -# seem to support this out of the box. Warning: Depending on the platform used, -# enabling this option may lead to badly anti-aliased labels on the edges of -# a graph (i.e. they become hard to read). - -DOT_TRANSPARENT = YES - -# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output -# files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) -# support this, this feature is disabled by default. - -DOT_MULTI_TARGETS = YES - -# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will -# generate a legend page explaining the meaning of the various boxes and -# arrows in the dot generated graphs. - -GENERATE_LEGEND = YES - -# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will -# remove the intermediate dot files that are used to generate -# the various graphs. - -DOT_CLEANUP = YES +SKIP_FUNCTION_MACROS = YES diff --git a/src/common/aka_common.cc b/src/common/aka_common.cc index 7b8bffb21..f4555b5b2 100644 --- a/src/common/aka_common.cc +++ b/src/common/aka_common.cc @@ -1,63 +1,63 @@ /** * @file aka_common.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Jun 11 16:56:43 2010 * * @brief Initialization of global variables * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "aka_static_memory.hh" #include "static_communicator.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ -void initialize(int * argc, char *** argv) { +void initialize(int & argc, char ** & argv) { AKANTU_DEBUG_IN(); StaticMemory::getStaticMemory(); StaticCommunicator * comm = StaticCommunicator::getStaticCommunicator(argc, argv); debug::debugger.setParallelContext(comm->whoAmI(), comm->getNbProc()); debug::initSignalHandler(); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void finalize() { AKANTU_DEBUG_IN(); if(StaticMemory::isInstantiated()) delete StaticMemory::getStaticMemory(); if(StaticCommunicator::isInstantiated()) { StaticCommunicator *comm = StaticCommunicator::getStaticCommunicator(); comm->barrier(); delete comm; } AKANTU_DEBUG_OUT(); } __END_AKANTU__ diff --git a/src/common/aka_common.hh b/src/common/aka_common.hh index 16eae10cc..61e39df31 100644 --- a/src/common/aka_common.hh +++ b/src/common/aka_common.hh @@ -1,386 +1,386 @@ /** * @file aka_common.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Jun 11 09:48:06 2010 * * @namespace akantu * * @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 <http://www.gnu.org/licenses/>. * * @section DESCRIPTION * * All common things to be included in the projects files * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_COMMON_HH__ #define __AKANTU_COMMON_HH__ /* -------------------------------------------------------------------------- */ #include <cmath> #include <cstdlib> #include <cstring> /* -------------------------------------------------------------------------- */ #include <iostream> #include <fstream> #include <iomanip> #include <string> #include <exception> #include <vector> #include <map> #include <set> #include <list> #include <limits> #include <algorithm> /* -------------------------------------------------------------------------- */ #define __BEGIN_AKANTU__ namespace akantu { #define __END_AKANTU__ } /* -------------------------------------------------------------------------- */ #include "aka_error.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ /* Common types */ /* -------------------------------------------------------------------------- */ typedef double Real; typedef unsigned int UInt; typedef unsigned long long UInt64; typedef signed int Int; typedef std::string ID; static const Real UINT_INIT_VALUE = 0; #ifdef AKANTU_NDEBUG static const Real REAL_INIT_VALUE = 0; #else static const Real REAL_INIT_VALUE = std::numeric_limits<Real>::quiet_NaN(); #endif /* -------------------------------------------------------------------------- */ /* Memory types */ /* -------------------------------------------------------------------------- */ typedef UInt MemoryID; /* -------------------------------------------------------------------------- */ /* Mesh/FEM/Model types */ /* -------------------------------------------------------------------------- */ typedef UInt Surface; /* -------------------------------------------------------------------------- */ /// @boost sequence of element to loop on in global tasks #define AKANTU_ELEMENT_TYPE \ (_segment_2) \ (_segment_3) \ (_triangle_3) \ (_triangle_6) \ (_tetrahedron_4) \ (_tetrahedron_10) \ (_quadrangle_4) \ (_quadrangle_8) \ (_hexahedron_8) \ (_point) \ (_bernoulli_beam_2) \ /// @enum ElementType type of element potentially contained in a Mesh enum ElementType { _not_defined = 0, _segment_2 = 1, /// first order segment _segment_3 = 2, /// second order segment _triangle_3 = 3, /// first order triangle _triangle_6 = 4, /// second order triangle _tetrahedron_4 = 5, /// first order tetrahedron _tetrahedron_10 = 6, /// second order tetrahedron @remark not implemented yet _quadrangle_4, /// first order quadrangle _quadrangle_8, /// second order quadrangle _hexahedron_8, /// first order hexahedron _point, /// point only for some algorithm to be generic like mesh partitioning _bernoulli_beam_2, /// bernoulli beam 2D _max_element_type }; /// @enum MaterialType different materials implemented enum MaterialType { _elastic = 0, _max_material_type }; /// myfunction(double * position, double * stress/force, double * normal, unsigned int material_id) typedef void (*BoundaryFunction)(double *,double *, double*, unsigned int); /// @enum BoundaryFunctionType type of function passed for boundary conditions enum BoundaryFunctionType { _bft_stress, _bft_forces }; /// @enum SparseMatrixType type of sparse matrix used enum SparseMatrixType { _unsymmetric, _symmetric }; /* -------------------------------------------------------------------------- */ /* Contact */ /* -------------------------------------------------------------------------- */ typedef ID ContactID; typedef ID ContactSearchID; typedef ID ContactNeighborStructureID; enum ContactType { _ct_not_defined = 0, _ct_2d_expli = 1, _ct_3d_expli = 2, _ct_rigid = 3 }; enum ContactSearchType { _cst_not_defined = 0, _cst_2d_expli = 1, _cst_expli = 2 }; enum ContactNeighborStructureType { _cnst_not_defined = 0, _cnst_regular_grid = 1, _cnst_2d_grid = 2 }; /* -------------------------------------------------------------------------- */ /* Ghosts handling */ /* -------------------------------------------------------------------------- */ typedef ID SynchronizerID; /// @enum CommunicatorType type of communication method to use enum CommunicatorType { _communicator_mpi, _communicator_dummy }; /// @enum SynchronizationTag type of synchronizations enum SynchronizationTag { /// SolidMechanicsModel tags _gst_smm_mass, /// synchronization of the SolidMechanicsModel.mass _gst_smm_for_strain, /// synchronization of the SolidMechanicsModel.current_position _gst_smm_boundary, /// synchronization of the boundary, forces, velocities and displacement _gst_smm_uv, /// synchronization of the nodal velocities and displacement /// HeatTransfer tags _gst_htm_capacity, /// synchronization of the nodal heat capacity _gst_htm_temperature, /// synchronization of the nodal temperature _gst_htm_gradient_temperature, /// synchronization of the element gradient temperature /// Material non local _gst_mnl_damage, /// synchronization of data to average in non local material /// Test tag _gst_test }; /// @enum GhostType type of ghost enum GhostType { _not_ghost, _ghost, _casper // not used but a real cute ghost }; /// @enum SynchronizerOperation reduce operation that the synchronizer can perform enum SynchronizerOperation { _so_sum, _so_min, _so_max, _so_null }; /* -------------------------------------------------------------------------- */ /* Global defines */ /* -------------------------------------------------------------------------- */ #define AKANTU_MIN_ALLOCATION 2000 #define AKANTU_INDENT " " #if !defined(__aka_inline__) # define __aka_inline__ #else # define AKANTU_INCLUDE_INLINE_IMPL #endif /* -------------------------------------------------------------------------- */ #define AKANTU_SET_MACRO(name, variable, type) \ inline void set##name (type variable) { \ this->variable = variable; \ } #define AKANTU_GET_MACRO(name, variable, type) \ inline type get##name () const { \ return variable; \ } #define AKANTU_GET_MACRO_NOT_CONST(name, variable, type) \ inline type get##name () { \ return variable; \ } #define AKANTU_GET_MACRO_BY_ELEMENT_TYPE_CONST(name, variable, type) \ inline const Vector<type> & \ get##name (const ::akantu::ElementType & el_type, \ const GhostType & ghost_type = _not_ghost) const { \ AKANTU_DEBUG_IN(); \ \ AKANTU_DEBUG_OUT(); \ return variable(el_type, ghost_type); \ } #define AKANTU_GET_MACRO_BY_ELEMENT_TYPE(name, variable, type) \ inline Vector<type> & \ get##name (const ::akantu::ElementType & el_type, \ const GhostType & ghost_type = _not_ghost) { \ AKANTU_DEBUG_IN(); \ \ AKANTU_DEBUG_OUT(); \ return variable(el_type, ghost_type); \ } /* -------------------------------------------------------------------------- */ //! standard output stream operator for ElementType inline std::ostream & operator <<(std::ostream & stream, ElementType type) { switch(type) { case _segment_2 : stream << "segment_2" ; break; case _segment_3 : stream << "segment_3" ; break; case _triangle_3 : stream << "triangle_3" ; break; case _triangle_6 : stream << "triangle_6" ; break; case _tetrahedron_4 : stream << "tetrahedron_4" ; break; case _tetrahedron_10 : stream << "tetrahedron_10"; break; case _quadrangle_4 : stream << "quadrangle_4" ; break; case _quadrangle_8 : stream << "quadrangle_8" ; break; case _hexahedron_8 : stream << "hexahedron_8" ; break; case _bernoulli_beam_2 : stream << "bernoulli_beam_2"; break; case _not_defined : stream << "undefined" ; break; case _max_element_type : stream << "ElementType(" << (int) type << ")"; break; case _point : stream << "point"; break; } return stream; } /// standard output stream operator for GhostType inline std::ostream & operator <<(std::ostream & stream, GhostType type) { switch(type) { case _not_ghost : stream << "not_ghost"; break; case _ghost : stream << "ghost" ; break; case _casper : stream << "Casper the friendly ghost"; break; } return stream; } /* -------------------------------------------------------------------------- */ -void initialize(int * argc, char *** argv); +void initialize(int & argc, char ** & argv); /* -------------------------------------------------------------------------- */ void finalize (); /* -------------------------------------------------------------------------- */ /* * For intel compiler annoying remark */ #if defined(__INTEL_COMPILER) /// remark #981: operands are evaluated in unspecified order #pragma warning ( disable : 981 ) /// remark #383: value copied to temporary, reference to temporary used #pragma warning ( disable : 383 ) #endif //defined(__INTEL_COMPILER) /* -------------------------------------------------------------------------- */ /* string manipulation */ /* -------------------------------------------------------------------------- */ inline void to_lower(std::string & str) { std::transform(str.begin(), str.end(), str.begin(), (int(*)(int))std::tolower); } /* -------------------------------------------------------------------------- */ inline void trim(std::string & to_trim) { size_t first = to_trim.find_first_not_of(" \t"); if (first != std::string::npos) { size_t last = to_trim.find_last_not_of(" \t"); to_trim = to_trim.substr(first, last - first + 1); } else to_trim = ""; } __END_AKANTU__ //#include "aka_types.hh" #if defined (AKANTU_INCLUDE_INLINE_IMPL) # include "aka_common_inline_impl.cc" #endif /* -------------------------------------------------------------------------- */ // BOOST PART: TOUCH ONLY IF YOU KNOW WHAT YOU ARE DOING #include <boost/preprocessor.hpp> #define AKANTU_BOOST_CASE_MACRO(r,macro,type) \ case type : { macro(type); break;} #define AKANTU_BOOST_ELEMENT_SWITCH(macro); \ do { \ switch(type) { \ BOOST_PP_SEQ_FOR_EACH(AKANTU_BOOST_CASE_MACRO,macro,AKANTU_ELEMENT_TYPE) \ case _not_defined: \ case _max_element_type: { \ AKANTU_DEBUG_ERROR("Wrong type : " << type); \ break; \ } \ } \ } while(0) #define AKANTU_BOOST_LIST_MACRO(r,macro,type) \ macro(type) #define AKANTU_BOOST_ELEMENT_LIST(macro) \ BOOST_PP_SEQ_FOR_EACH(AKANTU_BOOST_LIST_MACRO,macro,AKANTU_ELEMENT_TYPE) #endif /* __AKANTU_COMMON_HH__ */ diff --git a/src/fem/mesh.hh b/src/fem/mesh.hh index 2c810476d..0d12519de 100644 --- a/src/fem/mesh.hh +++ b/src/fem/mesh.hh @@ -1,580 +1,580 @@ /** * @file mesh.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Wed Jun 16 11:53:53 2010 * * @brief the class representing the meshes * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_MESH_HH__ #define __AKANTU_MESH_HH__ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "aka_memory.hh" #include "aka_vector.hh" #include "element_class.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ /* Element */ /* -------------------------------------------------------------------------- */ class Element { public: Element(ElementType type = _not_defined, UInt element = 0, GhostType ghost_type = _not_ghost) : type(type), element(element), ghost_type(ghost_type) {}; Element(const Element & element) { this->type = element.type; this->element = element.element; this->ghost_type = element.ghost_type; } virtual ~Element() {}; /// function to print the containt of the class virtual void printself(std::ostream & stream, int indent = 0) const; public: ElementType type; UInt element; GhostType ghost_type; }; struct CompElementLess { bool operator() (const Element& lhs, const Element& rhs) const { bool res = ((lhs.ghost_type < rhs.ghost_type) || ((lhs.ghost_type == rhs.ghost_type) && ((lhs.type < rhs.type) || ((lhs.type == rhs.type) && (lhs.element < rhs.element))))); return res; } }; extern const Element ElementNull; /* -------------------------------------------------------------------------- */ /* ByElementType */ /* -------------------------------------------------------------------------- */ template<class Stored> class ByElementType { protected: typedef std::map<ElementType, Stored> DataMap; public: ByElementType(const ID & id = "by_element_type", const ID & parent_id = ""); ~ByElementType(); inline static std::string printType(const ElementType & type, const GhostType & ghost_type); inline bool exists(ElementType type, GhostType ghost_type = _not_ghost) const; inline const Stored & operator()(const ElementType & type, const GhostType & ghost_type = _not_ghost) const; inline Stored & operator()(const ElementType & type, const GhostType & ghost_type = _not_ghost); inline Stored & operator()(const Stored & insert, const ElementType & type, const GhostType & ghost_type = _not_ghost); void printself(std::ostream & stream, int indent = 0) const; /* ------------------------------------------------------------------------ */ /* Element type Iterator */ /* ------------------------------------------------------------------------ */ class type_iterator : std::iterator<std::forward_iterator_tag, const ElementType> { public: typedef const ElementType value_type; typedef const ElementType* pointer; typedef const ElementType& reference; protected: typedef typename ByElementType<Stored>::DataMap::const_iterator DataMapIterator; public: type_iterator(DataMapIterator & list_begin, DataMapIterator & list_end, UInt dim); type_iterator(const type_iterator & it); inline reference operator*(); inline type_iterator & operator++(); type_iterator operator++(int); inline bool operator==(const type_iterator & other); inline bool operator!=(const type_iterator & other); private: DataMapIterator list_begin; DataMapIterator list_end; UInt dim; }; inline type_iterator firstType(UInt dim = 0, GhostType ghost_type = _not_ghost) const; inline type_iterator lastType(UInt dim = 0, GhostType ghost_type = _not_ghost) const; protected: inline DataMap & getData(GhostType ghost_type); inline const DataMap & getData(GhostType ghost_type) const; /* -------------------------------------------------------------------------- */ protected: ID id; DataMap data; DataMap ghost_data; }; /* -------------------------------------------------------------------------- */ /* Some typedefs */ /* -------------------------------------------------------------------------- */ template <typename T> class ByElementTypeVector : public ByElementType<Vector<T> *>, protected Memory { protected: typedef typename ByElementType<Vector<T> *>::DataMap DataMap; public: ByElementTypeVector() {}; // ByElementTypeVector(const ID & id = "by_element_type_vector", // const MemoryID & memory_id = 0) : // ByElementType<Vector<T> *>(id, memory_id) {}; ByElementTypeVector(const ID & id, const ID & parent_id, const MemoryID & memory_id = 0) : ByElementType<Vector<T> *>(id, parent_id), Memory(memory_id) {}; inline Vector<T> & alloc(UInt size, UInt nb_component, const ElementType & type, const GhostType & ghost_type); inline void alloc(UInt size, UInt nb_component, const ElementType & type); inline const Vector<T> & operator()(const ElementType & type, const GhostType & ghost_type = _not_ghost) const; inline Vector<T> & operator()(const ElementType & type, const GhostType & ghost_type = _not_ghost); inline void setVector(const ElementType & type, const GhostType & ghost_type, const Vector<T> & vect); inline void free(); }; /// to store data Vector<Real> by element type typedef ByElementTypeVector<Real> ByElementTypeReal; /// to store data Vector<Int> by element type typedef ByElementTypeVector<Int> ByElementTypeInt; /// to store data Vector<UInt> by element type typedef ByElementTypeVector<UInt> ByElementTypeUInt; /// Map of data of type UInt stored in a mesh typedef std::map<std::string, Vector<UInt> *> UIntDataMap; typedef ByElementType<UIntDataMap> ByElementTypeUIntDataMap; /* -------------------------------------------------------------------------- */ /* Mesh */ /* -------------------------------------------------------------------------- */ /** * @class Mesh this contain the coordinates of the nodes in the Mesh.nodes * Vector, and the connectivity. The connectivity are stored in by element * types. * * To know all the element types present in a mesh you can get the * Mesh::ConnectivityTypeList * * In order to loop on all element you have to loop on all types like this : * @code const Mesh::ConnectivityTypeList & type_list = mesh.getConnectivityTypeList(); Mesh::ConnectivityTypeList::const_iterator it; for(it = type_list.begin(); it != type_list.end(); ++it) { UInt nb_element = mesh.getNbElement(*it); UInt * conn = mesh.getConnectivity(*it).values; for(UInt e = 0; e < nb_element; ++e) { ... } } @endcode */ class Mesh : protected Memory { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: /// constructor that create nodes coordinates array Mesh(UInt spatial_dimension, const ID & id = "mesh" , const MemoryID & memory_id = 0); /// constructor that use an existing nodes coordinates array, by knowing its ID Mesh(UInt spatial_dimension, const ID & nodes_id, const ID & id = "mesh", const MemoryID & memory_id = 0); /** * constructor that use an existing nodes coordinates * array, by getting the vector of coordinates */ Mesh(UInt spatial_dimension, Vector<Real> & nodes, const ID & id = "mesh", const MemoryID & memory_id = 0); virtual ~Mesh(); /// @typedef ConnectivityTypeList list of the types present in a Mesh typedef std::set<ElementType> ConnectivityTypeList; // typedef Vector<Real> * NormalsMap[_max_element_type]; private: /// initialize the connectivity to NULL and other stuff void init(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// function to print the containt of the class virtual void printself(std::ostream & stream, int indent = 0) const; /// function that computes the bounding box (fills xmin, xmax) void computeBoundingBox(); /// init a by-element-type real vector with provided ids template<typename T> void initByElementTypeVector(ByElementTypeVector<T> & v, UInt nb_component, UInt size, const bool & flag_nb_node_per_elem_multiply=false) const; /// @todo: think about nicer way to do it /// extract coordinates of nodes from an element __aka_inline__ void extractNodalCoordinatesFromElement(Real * local_coords, UInt * connectivity, UInt n_nodes); /// extract coordinates of nodes from a reversed element __aka_inline__ void extractNodalCoordinatesFromPBCElement(Real * local_coords, UInt * connectivity, UInt n_nodes); /// convert a element to a linearized element __aka_inline__ UInt elementToLinearized(const Element & elem); /// convert a linearized element to an element __aka_inline__ Element linearizedToElement (UInt linearized_element); /// update the types offsets array for the conversions __aka_inline__ void updateTypesOffsets(const GhostType & ghost_type); /// add a Vector of connectivity for the type <type>. __aka_inline__ void addConnecticityType(const ElementType & type); /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: AKANTU_GET_MACRO(ID, id, const ID &); /// get the spatial dimension of the mesh = number of component of the coordinates AKANTU_GET_MACRO(SpatialDimension, spatial_dimension, UInt); /// get the nodes Vector aka coordinates AKANTU_GET_MACRO(Nodes, *nodes, const Vector<Real> &); /// get the number of nodes AKANTU_GET_MACRO(NbNodes, nodes->getSize(), UInt); /// get the Vector of global ids of the nodes (only used in parallel) AKANTU_GET_MACRO(GlobalNodesIds, *nodes_global_ids, const Vector<UInt> &); /// get the global id of a node __aka_inline__ UInt getNodeGlobalId(UInt local_id) const; /// get the global number of nodes __aka_inline__ UInt getNbGlobalNodes() const; /// get the nodes type Vector AKANTU_GET_MACRO(NodesType, *nodes_type, const Vector<Int> &); __aka_inline__ Int getNodeType(UInt local_id) const; /// say if a node is a pure ghost node __aka_inline__ bool isPureGhostNode(UInt n) const; /// say if a node is pur local or master node __aka_inline__ bool isLocalOrMasterNode(UInt n) const; __aka_inline__ bool isLocalNode(UInt n) const; __aka_inline__ bool isMasterNode(UInt n) const; __aka_inline__ bool isSlaveNode(UInt n) const; AKANTU_GET_MACRO(XMin, lower_bounds[0], Real); AKANTU_GET_MACRO(YMin, lower_bounds[1], Real); AKANTU_GET_MACRO(ZMin, lower_bounds[2], Real); AKANTU_GET_MACRO(XMax, upper_bounds[0], Real); AKANTU_GET_MACRO(YMax, upper_bounds[1], Real); AKANTU_GET_MACRO(ZMax, upper_bounds[2], Real); __aka_inline__ void getLowerBounds(Real * lower) const; __aka_inline__ void getUpperBounds(Real * upper) const; - inline void getLocalLowerBounds(Real * lower) const; - inline void getLocalUpperBounds(Real * upper) const; + __aka_inline__ void getLocalLowerBounds(Real * lower) const; + __aka_inline__ void getLocalUpperBounds(Real * upper) const; /// get the number of surfaces AKANTU_GET_MACRO(NbSurfaces, nb_surfaces, UInt); /// get the connectivity Vector for a given type AKANTU_GET_MACRO_BY_ELEMENT_TYPE_CONST(Connectivity, connectivities, UInt); /// @todo take out this set, if mesh can read surface id /// set the number of surfaces AKANTU_SET_MACRO(NbSurfaces, nb_surfaces, UInt); /// get the number of element of a type in the mesh __aka_inline__ UInt getNbElement(const ElementType & type, const GhostType & ghost_type = _not_ghost) const; // /// get the number of ghost element of a type in the mesh // __aka_inline__ UInt getNbGhostElement(const ElementType & type) const; /// get the connectivity list either for the elements or the ghost elements __aka_inline__ const ConnectivityTypeList & getConnectivityTypeList(const GhostType & ghost_type = _not_ghost) const; /// get the mesh of the internal facets __aka_inline__ const Mesh & getInternalFacetsMesh() const; /// compute the barycenter of a given element __aka_inline__ void getBarycenter(UInt element, const ElementType & type, Real * barycenter, GhostType ghost_type = _not_ghost) const; /// get the surface values of facets AKANTU_GET_MACRO_BY_ELEMENT_TYPE_CONST(SurfaceID, surface_id, UInt); /// set the int data to the surface id vectors __aka_inline__ void setSurfaceIDsFromIntData(std::string & data_name); __aka_inline__ const Vector<UInt> & getUIntData(const ElementType & el_type, const std::string & data_name, const GhostType & ghost_type = _not_ghost) const; /* ------------------------------------------------------------------------ */ /* Wrappers on ElementClass functions */ /* ------------------------------------------------------------------------ */ public: /// get the number of nodes per element for a given element type static __aka_inline__ UInt getNbNodesPerElement(const ElementType & type); /// get the number of nodes per element for a given element type considered as /// a first order element static __aka_inline__ ElementType getP1ElementType(const ElementType & type); /// get spatial dimension of a type of element static __aka_inline__ UInt getSpatialDimension(const ElementType & type); /// get number of facets of a given element type static __aka_inline__ UInt getNbFacetsPerElement(const ElementType & type); /// get number of facets of a given element type static __aka_inline__ UInt ** getFacetLocalConnectivity(const ElementType & type); /// get the type of the surface element associated to a given element static __aka_inline__ ElementType getFacetElementType(const ElementType & type); /// get the pointer to the list of elements for a given type __aka_inline__ Vector<UInt> * getReversedElementsPBCPointer(const ElementType & type); /* ------------------------------------------------------------------------ */ /* Element type Iterator */ /* ------------------------------------------------------------------------ */ typedef ByElementTypeUInt::type_iterator type_iterator; __aka_inline__ type_iterator firstType(UInt dim = 0, GhostType ghost_type = _not_ghost) const { return connectivities.firstType(dim, ghost_type); } __aka_inline__ type_iterator lastType(UInt dim = 0, GhostType ghost_type = _not_ghost) const { return connectivities.lastType(dim, ghost_type); } /* ------------------------------------------------------------------------ */ /* Private methods for friends */ /* ------------------------------------------------------------------------ */ private: friend class MeshIOMSH; friend class MeshIOMSHStruct; friend class MeshIODiana; friend class MeshUtils; friend class DistributedSynchronizer; AKANTU_GET_MACRO(NodesPointer, nodes, Vector<Real> *); /// get a pointer to the nodes_global_ids Vector<UInt> and create it if necessary __aka_inline__ Vector<UInt> * getNodesGlobalIdsPointer(); /// get a pointer to the nodes_type Vector<Int> and create it if necessary __aka_inline__ Vector<Int> * getNodesTypePointer(); /// get a pointer to the connectivity Vector for the given type and create it if necessary __aka_inline__ Vector<UInt> * getConnectivityPointer(const ElementType & type, const GhostType & ghost_type = _not_ghost); /// get a pointer to the internal_facets Mesh and create it if necessary __aka_inline__ Mesh * getInternalFacetsMeshPointer(); // __aka_inline__ Vector<Real> * getNormalsPointer(ElementType type) const; /// get a pointer to the surface_id Vector for the given type and create it if necessary __aka_inline__ Vector<UInt> * getSurfaceIDPointer(const ElementType & type, const GhostType & ghost_type = _not_ghost); /// get the UIntDataMap for a given ElementType __aka_inline__ UIntDataMap & getUIntDataMap(const ElementType & el_type, const GhostType & ghost_type = _not_ghost); /// get the IntDataMap pointer (moidifyable) for a given ElementType __aka_inline__ Vector<UInt> * getUIntDataPointer(const ElementType & el_type, const std::string & data_name, const GhostType & ghost_type = _not_ghost); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: /// id of the mesh ID id; /// array of the nodes coordinates Vector<Real> * nodes; /// global node ids Vector<UInt> * nodes_global_ids; /// node type, -3 pure ghost, -2 master for the node, -1 normal node, i in /// [0-N] slave node and master is proc i Vector<Int> * nodes_type; /// global number of nodes; UInt nb_global_nodes; /// boolean to know if the nodes have to be deleted with the mesh or not bool created_nodes; /// all class of elements present in this mesh (for heterogenous meshes) ByElementTypeUInt connectivities; /// map to normals for all class of elements present in this mesh ByElementTypeReal normals; /// list of all existing types in the mesh ConnectivityTypeList type_set; /// the spatial dimension of this mesh UInt spatial_dimension; /// internal facets mesh Mesh * internal_facets_mesh; /// types offsets Vector<UInt> types_offsets; /// list of all existing types in the mesh ConnectivityTypeList ghost_type_set; /// ghost types offsets Vector<UInt> ghost_types_offsets; /// number of surfaces present in this mesh UInt nb_surfaces; /// surface id of the surface elements in this mesh ByElementTypeUInt surface_id; /// min of coordinates Real lower_bounds[3]; /// max of coordinates Real upper_bounds[3]; /// size covered by the mesh on each direction Real size[3]; /// local min of coordinates Real local_lower_bounds[3]; /// local max of coordinates Real local_upper_bounds[3]; // /// list of elements that are reversed due to pbc // ByElementTypeUInt reversed_elements_pbc; // /// direction in which pbc are to be applied // UInt pbc_directions[3]; /// list of the vectors corresponding to tags in the mesh ByElementTypeUIntDataMap uint_data; }; /* -------------------------------------------------------------------------- */ /* Inline functions */ /* -------------------------------------------------------------------------- */ /// standard output stream operator inline std::ostream & operator <<(std::ostream & stream, const Element & _this) { _this.printself(stream); return stream; } #if defined (AKANTU_INCLUDE_INLINE_IMPL) # include "mesh_inline_impl.cc" #endif #include "by_element_type_tmpl.hh" /// standard output stream operator inline std::ostream & operator <<(std::ostream & stream, const Mesh & _this) { _this.printself(stream); return stream; } __END_AKANTU__ #endif /* __AKANTU_MESH_HH__ */ diff --git a/src/model/solid_mechanics/materials/material_elastic.hh b/src/model/solid_mechanics/materials/material_elastic.hh index cf353a476..1294bb21a 100644 --- a/src/model/solid_mechanics/materials/material_elastic.hh +++ b/src/model/solid_mechanics/materials/material_elastic.hh @@ -1,143 +1,146 @@ /** * @file material_elastic.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Jul 29 15:00:59 2010 * * @brief Material isotropic elastic * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_MATERIAL_ELASTIC_HH__ #define __AKANTU_MATERIAL_ELASTIC_HH__ __BEGIN_AKANTU__ /** * Material elastic isotropic * * parameters in the material files : * - rho : density (default: 0) * - E : Young's modulus (default: 0) * - nu : Poisson's ratio (default: 1/2) * - Plane_Stress : if 0: plane strain, else: plane stress (default: 0) */ class MaterialElastic : public virtual Material { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: MaterialElastic(Model & model, const ID & id = ""); virtual ~MaterialElastic() {}; /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: virtual void initMaterial(); virtual bool setParam(const std::string & key, const std::string & value, const ID & id); /// constitutive law for all element of a type virtual void computeStress(ElementType el_type, GhostType ghost_type = _not_ghost); /// compute the tangent stiffness matrix for an element type void computeTangentStiffness(const ElementType & el_type, Vector<Real> & tangent_matrix, GhostType ghost_type = _not_ghost); /// compute the celerity of wave in the material __aka_inline__ Real celerity(); /// function to print the containt of the class virtual void printself(std::ostream & stream, int indent = 0) const; protected: /// constitutive law for a given quadrature point __aka_inline__ void computeStress(Real * F, Real * sigma); // /// compute the tangent stiffness matrix for an element type template<UInt dim> void computeTangentStiffnessByDim(akantu::ElementType, akantu::Vector<Real>& tangent_matrix, akantu::GhostType); // /// compute the tangent stiffness matrix for an element template<UInt dim> void computeTangentStiffness(Real * tangent); /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: /// get the stable time step __aka_inline__ Real getStableTimeStep(Real h, const Element & element); + AKANTU_GET_MACRO(E, E, Real); + AKANTU_GET_MACRO(Nu, nu, Real); + /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: /// the young modulus Real E; /// Poisson coefficient Real nu; /// First Lamé coefficient Real lambda; /// Second Lamé coefficient (shear modulus) Real mu; /// Bulk modulus Real kpa; /// Plane stress or plane strain bool plane_stress; }; /* -------------------------------------------------------------------------- */ /* __aka_inline__ functions */ /* -------------------------------------------------------------------------- */ #if defined (AKANTU_INCLUDE_INLINE_IMPL) # include "material_elastic_inline_impl.cc" #endif /* -------------------------------------------------------------------------- */ /// standard output stream operator inline std::ostream & operator <<(std::ostream & stream, const MaterialElastic & _this) { _this.printself(stream); return stream; } __END_AKANTU__ #endif /* __AKANTU_MATERIAL_ELASTIC_HH__ */ diff --git a/src/model/solid_mechanics/solid_mechanics_model.cc b/src/model/solid_mechanics/solid_mechanics_model.cc index e95cd3a3b..f06b35244 100644 --- a/src/model/solid_mechanics/solid_mechanics_model.cc +++ b/src/model/solid_mechanics/solid_mechanics_model.cc @@ -1,893 +1,893 @@ /** * @file solid_mechanics_model.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Jul 22 14:35:38 2010 * * @brief Implementation of the SolidMechanicsModel class * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "solid_mechanics_model.hh" #include "aka_math.hh" #include "integration_scheme_2nd_order.hh" #include "static_communicator.hh" #include "dof_synchronizer.hh" #ifdef AKANTU_USE_MUMPS #include "solver_mumps.hh" #endif /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ SolidMechanicsModel::SolidMechanicsModel(Mesh & mesh, UInt dim, const ID & id, const MemoryID & memory_id) : Model(id, memory_id), time_step(NAN), f_m2a(1.0), mass_matrix(NULL), velocity_damping_matrix(NULL), stiffness_matrix(NULL), jacobian_matrix(NULL), element_material("element_material", id), integrator(NULL), increment_flag(false), solver(NULL), spatial_dimension(dim), mesh(mesh), dynamic(false), implicit(false) { AKANTU_DEBUG_IN(); createSynchronizerRegistry(this); if (spatial_dimension == 0) spatial_dimension = mesh.getSpatialDimension(); registerFEMObject<MyFEMType>("SolidMechanicsFEM", mesh, spatial_dimension); this->displacement = NULL; this->mass = NULL; this->velocity = NULL; this->acceleration = NULL; this->force = NULL; this->residual = NULL; this->boundary = NULL; this->increment = NULL; this->increment_acceleration = NULL; this->dof_synchronizer = NULL; materials.clear(); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ SolidMechanicsModel::~SolidMechanicsModel() { AKANTU_DEBUG_IN(); std::vector<Material *>::iterator mat_it; for(mat_it = materials.begin(); mat_it != materials.end(); ++mat_it) { delete *mat_it; } materials.clear(); delete integrator; if(solver) delete solver; if(mass_matrix) delete mass_matrix; if(velocity_damping_matrix) delete velocity_damping_matrix; if(stiffness_matrix && stiffness_matrix != jacobian_matrix) delete stiffness_matrix; if(jacobian_matrix) delete jacobian_matrix; if(dof_synchronizer) delete dof_synchronizer; AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ /* Initialisation */ /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::initFull(std::string material_file, - bool explicit_scheme, bool implicit_scheme, bool implicit_dynamic) { // initialize the model initModel(); // initialize the vectors initVectors(); - getForce().clear(); - getVelocity().clear(); - getAcceleration().clear(); - getDisplacement().clear(); - // initialize the time integration schemes - if(explicit_scheme) - initExplicit(); + // set the initial condition to 0 + force->clear(); + velocity->clear(); + acceleration->clear(); + displacement->clear(); + // initialize the time integration schemes if(implicit_scheme) initImplicit(implicit_dynamic); + else + initExplicit(); // initialize the materials if(material_file != "") { readMaterials(material_file); initMaterials(); } } void SolidMechanicsModel::initParallel(MeshPartition * partition, DataAccessor * data_accessor) { AKANTU_DEBUG_IN(); if (data_accessor == NULL) data_accessor = this; Synchronizer & synch_parallel = createParallelSynch(partition,data_accessor); synch_registry->registerSynchronizer(synch_parallel,_gst_smm_mass); synch_registry->registerSynchronizer(synch_parallel,_gst_smm_for_strain); synch_registry->registerSynchronizer(synch_parallel,_gst_smm_boundary); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::initFEMBoundary(bool create_surface) { if(create_surface) MeshUtils::buildFacets(mesh, true, false); FEM & fem_boundary = getFEMBoundary(); fem_boundary.initShapeFunctions(); fem_boundary.computeNormalsOnControlPoints(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::initExplicit() { AKANTU_DEBUG_IN(); if (integrator) delete integrator; integrator = new CentralDifference(); dynamic = true; implicit = false; AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::initVectors() { AKANTU_DEBUG_IN(); UInt nb_nodes = mesh.getNbNodes(); std::stringstream sstr_disp; sstr_disp << id << ":displacement"; std::stringstream sstr_mass; sstr_mass << id << ":mass"; std::stringstream sstr_velo; sstr_velo << id << ":velocity"; std::stringstream sstr_acce; sstr_acce << id << ":acceleration"; std::stringstream sstr_forc; sstr_forc << id << ":force"; std::stringstream sstr_resi; sstr_resi << id << ":residual"; std::stringstream sstr_boun; sstr_boun << id << ":boundary"; displacement = &(alloc<Real>(sstr_disp.str(), nb_nodes, spatial_dimension, REAL_INIT_VALUE)); mass = &(alloc<Real>(sstr_mass.str(), nb_nodes, spatial_dimension, 0)); velocity = &(alloc<Real>(sstr_velo.str(), nb_nodes, spatial_dimension, REAL_INIT_VALUE)); acceleration = &(alloc<Real>(sstr_acce.str(), nb_nodes, spatial_dimension, REAL_INIT_VALUE)); force = &(alloc<Real>(sstr_forc.str(), nb_nodes, spatial_dimension, REAL_INIT_VALUE)); residual = &(alloc<Real>(sstr_resi.str(), nb_nodes, spatial_dimension, REAL_INIT_VALUE)); boundary = &(alloc<bool>(sstr_boun.str(), nb_nodes, spatial_dimension, false)); std::stringstream sstr_curp; sstr_curp << id << ":current_position"; current_position = &(alloc<Real>(sstr_curp.str(), 0, spatial_dimension, REAL_INIT_VALUE)); for(UInt g = _not_ghost; g <= _ghost; ++g) { GhostType gt = (GhostType) g; const Mesh::ConnectivityTypeList & type_list = mesh.getConnectivityTypeList(gt); Mesh::ConnectivityTypeList::const_iterator it; for(it = type_list.begin(); it != type_list.end(); ++it) { UInt nb_element = mesh.getNbElement(*it, gt); element_material.alloc(nb_element, 1, *it, gt); } } dof_synchronizer = new DOFSynchronizer(mesh, spatial_dimension); dof_synchronizer->initLocalDOFEquationNumbers(); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::initModel() { /// \todo add the current position as a parameter to initShapeFunctions for /// large deformation getFEM().initShapeFunctions(_not_ghost); getFEM().initShapeFunctions(_ghost); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::initPBC(UInt x, UInt y, UInt z){ Model::initPBC(x,y,z); PBCSynchronizer * synch = new PBCSynchronizer(pbc_pair); synch_registry->registerSynchronizer(*synch, _gst_smm_uv); synch_registry->registerSynchronizer(*synch, _gst_smm_mass); changeLocalEquationNumberforPBC(pbc_pair, mesh.getSpatialDimension()); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::updateCurrentPosition() { AKANTU_DEBUG_IN(); UInt nb_nodes = mesh.getNbNodes(); current_position->resize(nb_nodes); //Vector<Real> * current_position = new Vector<Real>(nb_nodes, spatial_dimension, NAN, "position"); Real * current_position_val = current_position->values; Real * position_val = mesh.getNodes().values; Real * displacement_val = displacement->values; /// compute current_position = initial_position + displacement memcpy(current_position_val, position_val, nb_nodes*spatial_dimension*sizeof(Real)); for (UInt n = 0; n < nb_nodes*spatial_dimension; ++n) { *current_position_val++ += *displacement_val++; } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::initializeUpdateResidualData() { AKANTU_DEBUG_IN(); UInt nb_nodes = mesh.getNbNodes(); residual->resize(nb_nodes); /// copy the forces in residual for boundary conditions memcpy(residual->values, force->values, nb_nodes*spatial_dimension*sizeof(Real)); updateCurrentPosition(); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ /* Explicit scheme */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::updateResidual(bool need_initialize) { AKANTU_DEBUG_IN(); // f = f_ext - f_int - Ma - Cv // f = f_ext if (need_initialize) initializeUpdateResidualData(); // f -= fint /// start synchronization synch_registry->asynchronousSynchronize(_gst_smm_for_strain); /// call update residual on each local elements std::vector<Material *>::iterator mat_it; for(mat_it = materials.begin(); mat_it != materials.end(); ++mat_it) { //(*mat_it)->updateResidual(*current_position, _not_ghost); (*mat_it)->updateResidual(*displacement, _not_ghost); } /// finalize communications synch_registry->waitEndSynchronize(_gst_smm_for_strain); /// call update residual on each ghost elements for(mat_it = materials.begin(); mat_it != materials.end(); ++mat_it) { //(*mat_it)->updateResidual(*current_position, _ghost); (*mat_it)->updateResidual(*displacement, _ghost); } if(dynamic) { // f -= Ma if(mass_matrix) { // if full mass_matrix Vector<Real> * Ma = new Vector<Real>(*acceleration, true, "Ma"); *Ma *= *mass_matrix; *residual -= *Ma; delete Ma; std::cout << "A-Hoy !" << std::endl; } else { // else lumped mass UInt nb_nodes = acceleration->getSize(); UInt nb_degre_of_freedom = acceleration->getNbComponent(); Real * mass_val = mass->values; Real * accel_val = acceleration->values; Real * res_val = residual->values; bool * boundary_val = boundary->values; for (UInt n = 0; n < nb_nodes * nb_degre_of_freedom; ++n) { if(!(*boundary_val)) { *res_val -= *accel_val * *mass_val; } boundary_val++; res_val++; mass_val++; accel_val++; } } // f -= Cv if(velocity_damping_matrix) { Vector<Real> * Cv = new Vector<Real>(*velocity); *Cv *= *velocity_damping_matrix; *residual -= *Cv; delete Cv; } } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::updateAcceleration() { AKANTU_DEBUG_IN(); UInt nb_nodes = acceleration->getSize(); UInt nb_degre_of_freedom = acceleration->getNbComponent(); if(!increment_acceleration) increment_acceleration = new Vector<Real>(nb_nodes, nb_degre_of_freedom); increment_acceleration->resize(nb_nodes); increment_acceleration->clear(); if(!implicit && !mass_matrix) { Real * mass_val = mass->values; Real * residual_val = residual->values; bool * boundary_val = boundary->values; Real * inc = increment_acceleration->values; Real * accel_val = acceleration->values; for (UInt n = 0; n < nb_nodes; ++n) { for (UInt d = 0; d < nb_degre_of_freedom; d++) { if(!(*boundary_val)) { *inc = f_m2a * (*residual_val / *mass_val); } residual_val++; boundary_val++; inc++; mass_val++; accel_val++; } } } else { solveDynamic<NewmarkBeta::_acceleration_corrector>(*increment_acceleration); } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::explicitPred() { AKANTU_DEBUG_IN(); if(increment_flag) { memcpy(increment->values, displacement->values, displacement->getSize()*displacement->getNbComponent()*sizeof(Real)); } AKANTU_DEBUG_ASSERT(integrator,"itegrator should have been allocated: " << "have called initExplicit ? " << "or initImplicit ?"); integrator->integrationSchemePred(time_step, *displacement, *velocity, *acceleration, *boundary); if(increment_flag) { Real * inc_val = increment->values; Real * dis_val = displacement->values; UInt nb_nodes = displacement->getSize(); for (UInt n = 0; n < nb_nodes; ++n) { *inc_val = *dis_val - *inc_val; inc_val++; dis_val++; } } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::explicitCorr() { AKANTU_DEBUG_IN(); integrator->integrationSchemeCorrAccel(time_step, *displacement, *velocity, *acceleration, *boundary, *increment_acceleration); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ /* Implicit scheme */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::initSolver() { #if !defined(AKANTU_USE_MUMPS) // or other solver in the future \todo add AKANTU_HAS_SOLVER in CMake AKANTU_DEBUG_ERROR("You should at least activate one solver."); #else UInt nb_global_node = mesh.getNbGlobalNodes(); std::stringstream sstr; sstr << id << ":jacobian_matrix"; jacobian_matrix = new SparseMatrix(nb_global_node * spatial_dimension, _symmetric, spatial_dimension, sstr.str(), memory_id); dof_synchronizer->initGlobalDOFEquationNumbers(); jacobian_matrix->buildProfile(mesh, *dof_synchronizer); #ifdef AKANTU_USE_MUMPS std::stringstream sstr_solv; sstr_solv << id << ":solver"; solver = new SolverMumps(*jacobian_matrix, sstr_solv.str()); dof_synchronizer->initScatterGatherCommunicationScheme(); #else AKANTU_DEBUG_ERROR("You should at least activate one solver."); #endif //AKANTU_USE_MUMPS solver->initialize(); #endif //AKANTU_HAS_SOLVER } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::initImplicit(bool dynamic) { AKANTU_DEBUG_IN(); this->dynamic = dynamic; implicit = true; initSolver(); if(dynamic) { if(integrator) delete integrator; integrator = new TrapezoidalRule2(); std::stringstream sstr; sstr << id << ":stiffness_matrix"; stiffness_matrix = new SparseMatrix(*jacobian_matrix, sstr.str(), memory_id); } else { stiffness_matrix = jacobian_matrix; } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::initialAcceleration() { AKANTU_DEBUG_IN(); AKANTU_DEBUG_INFO("Solving Ma = f"); Solver * acc_solver = NULL; #ifdef AKANTU_USE_MUMPS std::stringstream sstr; sstr << id << ":solver_mass_matrix"; acc_solver = new SolverMumps(*mass_matrix, sstr.str()); dof_synchronizer->initScatterGatherCommunicationScheme(); #else AKANTU_DEBUG_ERROR("You should at least activate one solver."); #endif //AKANTU_USE_MUMPS acc_solver->initialize(); mass_matrix->applyBoundary(*boundary); acc_solver->setRHS(*residual); acc_solver->solve(*acceleration); delete acc_solver; AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::assembleStiffnessMatrix() { AKANTU_DEBUG_IN(); stiffness_matrix->clear(); /// call compute stiffness matrix on each local elements std::vector<Material *>::iterator mat_it; for(mat_it = materials.begin(); mat_it != materials.end(); ++mat_it) { (*mat_it)->assembleStiffnessMatrix(*displacement, _not_ghost); } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::solveDynamic() { AKANTU_DEBUG_IN(); AKANTU_DEBUG_ASSERT(stiffness_matrix != NULL, "You should first initialize the implicit solver and assemble the stiffness matrix"); AKANTU_DEBUG_ASSERT(mass_matrix != NULL, "You should first initialize the implicit solver and assemble the mass matrix"); if(!increment) setIncrementFlagOn(); solveDynamic<NewmarkBeta::_displacement_corrector>(*increment); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::solveStatic() { AKANTU_DEBUG_IN(); AKANTU_DEBUG_INFO("Solving Ku = f"); AKANTU_DEBUG_ASSERT(stiffness_matrix != NULL, "You should first initialize the implicit solver and assemble the stiffness matrix"); UInt nb_nodes = displacement->getSize(); UInt nb_degre_of_freedom = displacement->getNbComponent(); stiffness_matrix->applyBoundary(*boundary); if(dynamic) jacobian_matrix->copyContent(*stiffness_matrix); solver->setRHS(*residual); if(!increment) setIncrementFlagOn(); solver->solve(*increment); Real * increment_val = increment->values; Real * displacement_val = displacement->values; bool * boundary_val = boundary->values; for (UInt n = 0; n < nb_nodes * nb_degre_of_freedom; ++n) { if(!(*boundary_val)) { *displacement_val += *increment_val; } displacement_val++; boundary_val++; increment_val++; } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ bool SolidMechanicsModel::testConvergenceIncrement(Real tolerance) { Real error; bool tmp = testConvergenceIncrement(tolerance, error); AKANTU_DEBUG_INFO("Norm of increment : " << error); return tmp; } /* -------------------------------------------------------------------------- */ bool SolidMechanicsModel::testConvergenceIncrement(Real tolerance, Real & error) { AKANTU_DEBUG_IN(); UInt nb_nodes = displacement->getSize(); UInt nb_degre_of_freedom = displacement->getNbComponent(); error = 0; Real norm[2] = {0., 0.}; Real * increment_val = increment->storage(); bool * boundary_val = boundary->storage(); Real * displacement_val = displacement->storage(); for (UInt n = 0; n < nb_nodes; ++n) { bool is_local_node = mesh.isLocalOrMasterNode(n); for (UInt d = 0; d < nb_degre_of_freedom; ++d) { if(!(*boundary_val) && is_local_node) { norm[0] += *increment_val * *increment_val; norm[1] += *displacement_val * *displacement_val; } boundary_val++; increment_val++; displacement_val++; } } StaticCommunicator::getStaticCommunicator()->allReduce(norm, 2, _so_sum); norm[0] = sqrt(norm[0]); norm[1] = sqrt(norm[1]); AKANTU_DEBUG_ASSERT(!Math::isnan(norm[0]), "Something goes wrong in the solve phase"); std::cout << norm[0] << " " << norm[1] << std::endl; AKANTU_DEBUG_OUT(); error = norm[0] / norm[1]; return (error < tolerance); } /* -------------------------------------------------------------------------- */ bool SolidMechanicsModel::testConvergenceResidual(Real tolerance) { Real error; bool tmp = testConvergenceResidual(tolerance, error); AKANTU_DEBUG_INFO("Norm of residual : " << error); return tmp; } /* -------------------------------------------------------------------------- */ bool SolidMechanicsModel::testConvergenceResidual(Real tolerance, Real & norm) { AKANTU_DEBUG_IN(); UInt nb_nodes = residual->getSize(); norm = 0; Real * residual_val = residual->values; bool * boundary_val = boundary->values; for (UInt n = 0; n < nb_nodes; ++n) { bool is_local_node = mesh.isLocalOrMasterNode(n); if(is_local_node) { for (UInt d = 0; d < spatial_dimension; ++d) { if(!(*boundary_val)) { norm += *residual_val * *residual_val; } boundary_val++; residual_val++; } } else { boundary_val += spatial_dimension; residual_val += spatial_dimension; } } StaticCommunicator::getStaticCommunicator()->allReduce(&norm, 1, _so_sum); norm = sqrt(norm); AKANTU_DEBUG_ASSERT(!Math::isnan(norm), "Something goes wrong in the solve phase"); AKANTU_DEBUG_OUT(); return (norm < tolerance); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::implicitPred() { AKANTU_DEBUG_IN(); integrator->integrationSchemePred(time_step, *displacement, *velocity, *acceleration, *boundary); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::implicitCorr() { AKANTU_DEBUG_IN(); integrator->integrationSchemeCorrDispl(time_step, *displacement, *velocity, *acceleration, *boundary, *increment); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ /* Information */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::synchronizeBoundaries() { AKANTU_DEBUG_IN(); AKANTU_DEBUG_ASSERT(synch_registry,"Synchronizer registry was not initialized." << " Did you call initParallel ?"); synch_registry->synchronize(_gst_smm_boundary); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::setIncrementFlagOn() { AKANTU_DEBUG_IN(); if(!increment) { UInt nb_nodes = mesh.getNbNodes(); std::stringstream sstr_inc; sstr_inc << id << ":increment"; increment = &(alloc<Real>(sstr_inc.str(), nb_nodes, spatial_dimension, 0)); } increment_flag = true; AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ Real SolidMechanicsModel::getStableTimeStep() { AKANTU_DEBUG_IN(); Real min_dt = getStableTimeStep(_not_ghost); /// reduction min over all processors StaticCommunicator::getStaticCommunicator()->allReduce(&min_dt, 1, _so_min); AKANTU_DEBUG_OUT(); return min_dt; } /* -------------------------------------------------------------------------- */ Real SolidMechanicsModel::getStableTimeStep(const GhostType & ghost_type) { AKANTU_DEBUG_IN(); Material ** mat_val = &(materials.at(0)); Real min_dt = std::numeric_limits<Real>::max(); Real * coord = mesh.getNodes().values; Real * disp_val = displacement->values; Element elem; elem.ghost_type = ghost_type; const Mesh::ConnectivityTypeList & type_list = mesh.getConnectivityTypeList(ghost_type); Mesh::ConnectivityTypeList::const_iterator it; for(it = type_list.begin(); it != type_list.end(); ++it) { if(mesh.getSpatialDimension(*it) != spatial_dimension) continue; elem.type = *it; UInt nb_nodes_per_element = mesh.getNbNodesPerElement(*it); UInt nb_element = mesh.getNbElement(*it); UInt * conn = mesh.getConnectivity(*it, ghost_type).storage(); UInt * elem_mat_val = element_material(*it, ghost_type).storage(); Real * u = new Real[nb_nodes_per_element*spatial_dimension]; for (UInt el = 0; el < nb_element; ++el) { UInt el_offset = el * nb_nodes_per_element; elem.element = el; for (UInt n = 0; n < nb_nodes_per_element; ++n) { UInt offset_conn = conn[el_offset + n] * spatial_dimension; memcpy(u + n * spatial_dimension, coord + offset_conn, spatial_dimension * sizeof(Real)); for (UInt i = 0; i < spatial_dimension; ++i) { u[n * spatial_dimension + i] += disp_val[offset_conn + i]; } } Real el_size = getFEM().getElementInradius(u, *it); Real el_dt = mat_val[elem_mat_val[el]]->getStableTimeStep(el_size, elem); min_dt = min_dt > el_dt ? el_dt : min_dt; } delete [] u; } AKANTU_DEBUG_OUT(); return min_dt; } /* -------------------------------------------------------------------------- */ Real SolidMechanicsModel::getPotentialEnergy() { AKANTU_DEBUG_IN(); Real epot = 0.; /// call update residual on each local elements std::vector<Material *>::iterator mat_it; for(mat_it = materials.begin(); mat_it != materials.end(); ++mat_it) { epot += (*mat_it)->getPotentialEnergy(); } /// reduction sum over all processors StaticCommunicator::getStaticCommunicator()->allReduce(&epot, 1, _so_sum); AKANTU_DEBUG_OUT(); return epot; } /* -------------------------------------------------------------------------- */ Real SolidMechanicsModel::getKineticEnergy() { AKANTU_DEBUG_IN(); Real ekin = 0.; UInt nb_nodes = mesh.getNbNodes(); Real * vel_val = velocity->values; Real * mass_val = mass->values; for (UInt n = 0; n < nb_nodes; ++n) { Real mv2 = 0; bool is_local_node = mesh.isLocalOrMasterNode(n); for (UInt i = 0; i < spatial_dimension; ++i) { // if(is_local_node) { mv2 += is_local_node * *vel_val * *vel_val * *mass_val; // } vel_val++; mass_val++; } ekin += mv2; } StaticCommunicator::getStaticCommunicator()->allReduce(&ekin, 1, _so_sum); AKANTU_DEBUG_OUT(); return ekin * .5; } /* -------------------------------------------------------------------------- */ void SolidMechanicsModel::printself(std::ostream & stream, int indent) const { std::string space; for(Int i = 0; i < indent; i++, space += AKANTU_INDENT); stream << space << "Solid Mechanics Model [" << std::endl; stream << space << " + id : " << id << std::endl; stream << space << " + spatial dimension : " << spatial_dimension << std::endl; stream << space << " + fem [" << std::endl; getFEM().printself(stream, indent + 2); stream << space << AKANTU_INDENT << "]" << std::endl; stream << space << " + nodals information [" << std::endl; displacement->printself(stream, indent + 2); mass ->printself(stream, indent + 2); velocity ->printself(stream, indent + 2); acceleration->printself(stream, indent + 2); force ->printself(stream, indent + 2); residual ->printself(stream, indent + 2); boundary ->printself(stream, indent + 2); stream << space << AKANTU_INDENT << "]" << std::endl; stream << space << " + connectivity type information [" << std::endl; element_material.printself(stream, indent + 2); stream << space << AKANTU_INDENT << "]" << std::endl; stream << space << "]" << std::endl; } /* -------------------------------------------------------------------------- */ __END_AKANTU__ diff --git a/src/model/solid_mechanics/solid_mechanics_model.hh b/src/model/solid_mechanics/solid_mechanics_model.hh index 1bb3b0b30..5bdad7718 100644 --- a/src/model/solid_mechanics/solid_mechanics_model.hh +++ b/src/model/solid_mechanics/solid_mechanics_model.hh @@ -1,486 +1,486 @@ /** * @file solid_mechanics_model.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date[creation] Thu Jul 22 11:51:06 2010 * @date[last modification] Thu Oct 14 14:00:06 2010 * * @brief Model of Solid Mechanics * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_SOLID_MECHANICS_MODEL_HH__ #define __AKANTU_SOLID_MECHANICS_MODEL_HH__ /* -------------------------------------------------------------------------- */ #include <fstream> /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "model.hh" #include "data_accessor.hh" #include "material.hh" #include "integrator_gauss.hh" #include "shape_lagrange.hh" #include "aka_types.hh" #include "integration_scheme_2nd_order.hh" /* -------------------------------------------------------------------------- */ namespace akantu { // class Material; class IntegrationScheme2ndOrder; class Contact; class Solver; class SparseMatrix; } __BEGIN_AKANTU__ class SolidMechanicsModel : public Model, public DataAccessor { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: typedef FEMTemplate<IntegratorGauss,ShapeLagrange> MyFEMType; SolidMechanicsModel(Mesh & mesh, UInt spatial_dimension = 0, const ID & id = "solid_mechanics_model", const MemoryID & memory_id = 0); virtual ~SolidMechanicsModel(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// initialize completely the model void initFull(std::string material_file = "", - bool explicit_scheme = true, - bool implicit_scheme = false, bool implicit_dynamic = false); + bool implicit_scheme = false, + bool implicit_dynamic = false); /// initialize the fem object needed for boundary conditions void initFEMBoundary(bool create_surface = true); /// register the tags associated with the parallel synchronizer void initParallel(MeshPartition * partition, DataAccessor * data_accessor=NULL); /// allocate all vectors void initVectors(); /// initialize all internal arrays for materials void initMaterials(); /// initialize the model void initModel(); /// init PBC synchronizer void initPBC(UInt x,UInt y, UInt z); /// function to print the containt of the class virtual void printself(std::ostream & stream, int indent = 0) const; /* ------------------------------------------------------------------------ */ /* PBC */ /* ------------------------------------------------------------------------ */ public: /// change the equation number for proper assembly when using PBC void changeEquationNumberforPBC(std::map<UInt,UInt> & pbc_pair); /* ------------------------------------------------------------------------ */ /* Explicit */ /* ------------------------------------------------------------------------ */ public: /// initialize the stuff for the explicit scheme void initExplicit(); /// initialize the array needed by updateResidual (residual, current_position) void initializeUpdateResidualData(); /// update the current position vector void updateCurrentPosition(); /// assemble the residual for the explicit scheme void updateResidual(bool need_initialize = true); /** * \brief compute the acceleration from the residual * this function is the explicit equivalent to solveDynamic in implicit * In the case of lumped mass just divide the residual by the mass * In the case of not lumped mass call solveDynamic<_acceleration_corrector> */ void updateAcceleration(); /// explicit integration predictor void explicitPred(); /// explicit integration corrector void explicitCorr(); /* ------------------------------------------------------------------------ */ /* Implicit */ /* ------------------------------------------------------------------------ */ public: /// initialize the solver and the jacobian_matrix (called by initImplicit) void initSolver(); /// initialize the stuff for the implicit solver void initImplicit(bool dynamic = false); /// solve Ma = f to get the initial acceleration void initialAcceleration(); /// assemble the stiffness matrix void assembleStiffnessMatrix(); /// solve @f[ A\delta u = f_ext - f_int @f] in displacement void solveDynamic(); /// solve Ku = f void solveStatic(); /// test the convergence (norm of increment) bool testConvergenceIncrement(Real tolerance); bool testConvergenceIncrement(Real tolerance, Real & error); /// test the convergence (norm of residual) bool testConvergenceResidual(Real tolerance); bool testConvergenceResidual(Real tolerance, Real & error); /// implicit time integration predictor void implicitPred(); /// implicit time integration corrector void implicitCorr(); private: /// compute A and solve @f[ A\delta u = f_ext - f_int @f] template<NewmarkBeta::IntegrationSchemeCorrectorType type> void solveDynamic(Vector<Real> & increment); /* ------------------------------------------------------------------------ */ /* Boundaries (solid_mechanics_model_boundary.cc) */ /* ------------------------------------------------------------------------ */ public: /// compute force vector from a function(x,y,z) that describe stresses void computeForcesFromFunction(BoundaryFunction in_function, BoundaryFunctionType function_type); /// integrate a force on the boundary by providing a stress tensor void computeForcesByStressTensor(const Vector<Real> & stresses, const ElementType & type, const GhostType & ghost_type); /// integrate a force on the boundary by providing a traction vector void computeForcesByTractionVector(const Vector<Real> & tractions, const ElementType & type, const GhostType & ghost_type); /// synchronize the ghost element boundaries values void synchronizeBoundaries(); /* ------------------------------------------------------------------------ */ /* Materials (solid_mechanics_model_material.cc) */ /* ------------------------------------------------------------------------ */ public: /// read the material files to instantiate all the materials void readMaterials(const std::string & filename); /// read a custom material with a keyword and class as template template <typename M> UInt readCustomMaterial(const std::string & filename, const std::string & keyword); private: /// read properties part of a material file and create the material template <typename M> Material * readMaterialProperties(std::ifstream & infile, ID mat_id, UInt ¤t_line); /* ------------------------------------------------------------------------ */ /* Mass (solid_mechanics_model_mass.cc) */ /* ------------------------------------------------------------------------ */ public: /// assemble the lumped mass matrix void assembleMassLumped(); /// assemble the mass matrix void assembleMass(); private: /// assemble the lumped mass matrix for local and ghost elements void assembleMassLumped(GhostType ghost_type); void assembleMass(GhostType ghost_type); /// fill a vector of rho void computeRho(Vector<Real> & rho, ElementType type, GhostType ghost_type); /* ------------------------------------------------------------------------ */ /* Data Accessor inherited members */ /* ------------------------------------------------------------------------ */ public: __aka_inline__ virtual UInt getNbDataToPack(const Element & element, SynchronizationTag tag) const; __aka_inline__ virtual UInt getNbDataToUnpack(const Element & element, SynchronizationTag tag) const; __aka_inline__ virtual void packData(CommunicationBuffer & buffer, const Element & element, SynchronizationTag tag) const; __aka_inline__ virtual void unpackData(CommunicationBuffer & buffer, const Element & element, SynchronizationTag tag); __aka_inline__ virtual UInt getNbDataToPack(SynchronizationTag tag) const; __aka_inline__ virtual UInt getNbDataToUnpack(SynchronizationTag tag) const; __aka_inline__ virtual void packData(CommunicationBuffer & buffer, const UInt index, SynchronizationTag tag) const; __aka_inline__ virtual void unpackData(CommunicationBuffer & buffer, const UInt index, SynchronizationTag tag); /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: /// return the dimension of the system space AKANTU_GET_MACRO(SpatialDimension, spatial_dimension, UInt); /// get the current value of the time step AKANTU_GET_MACRO(TimeStep, time_step, Real); /// set the value of the time step AKANTU_SET_MACRO(TimeStep, time_step, Real); /// get the value of the conversion from forces/ mass to acceleration AKANTU_GET_MACRO(F_M2A, f_m2a, Real); /// set the value of the conversion from forces/ mass to acceleration AKANTU_SET_MACRO(F_M2A, f_m2a, Real); /// get the SolidMechanicsModel::displacement vector AKANTU_GET_MACRO(Displacement, *displacement, Vector<Real> &); /** * @brief get the SolidMechanicsModel::current_position vector \warn only * consistent after a call to SolidMechanicsModel::updateCurrentPosition */ AKANTU_GET_MACRO(CurrentPosition, *current_position, const Vector<Real> &); /** * @brief get the SolidMechanicsModel::increment vector \warn only consistent * if SolidMechanicsModel::setIncrementFlagOn has been called before */ AKANTU_GET_MACRO(Increment, *increment, const Vector<Real> &); /// get the lumped SolidMechanicsModel::mass vector AKANTU_GET_MACRO(Mass, *mass, const Vector<Real> &); /// get the SolidMechanicsModel::velocity vector AKANTU_GET_MACRO(Velocity, *velocity, Vector<Real> &); /** * @brief get the SolidMechanicsModel::acceleration vector, updated by * SolidMechanicsModel::updateAcceleration */ AKANTU_GET_MACRO(Acceleration, *acceleration, Vector<Real> &); /// get the SolidMechnicsModel::incrementAcceleration vector AKANTU_GET_MACRO(IncrementAcceleration, *increment_acceleration, Vector<Real> &); /// get the SolidMechanicsModel::force vector (boundary forces) AKANTU_GET_MACRO(Force, *force, Vector<Real> &); /// get the SolidMechanicsModel::residual vector, computed by SolidMechanicsModel::updateResidual AKANTU_GET_MACRO(Residual, *residual, const Vector<Real> &); /// get the SolidMechanicsModel::boundary vector AKANTU_GET_MACRO(Boundary, *boundary, Vector<bool> &); /// get the value of the SolidMechanicsModel::increment_flag AKANTU_GET_MACRO(IncrementFlag, increment_flag, bool); /// get the SolidMechanicsModel::element_material vector corresponding to a given akantu::ElementType AKANTU_GET_MACRO_BY_ELEMENT_TYPE(ElementMaterial, element_material, UInt); /// get a particular material __aka_inline__ Material & getMaterial(UInt mat_index); __aka_inline__ const Material & getMaterial(UInt mat_index) const; /// give the number of materials __aka_inline__ UInt getNbMaterials() { return materials.size(); }; /// compute the stable time step Real getStableTimeStep(); /// compute the potential energy Real getPotentialEnergy(); /// compute the kinetic energy Real getKineticEnergy(); /// set the Contact object AKANTU_SET_MACRO(Contact, contact, Contact *); /** * @brief set the SolidMechanicsModel::increment_flag to on, the activate the * update of the SolidMechanicsModel::increment vector */ void setIncrementFlagOn(); /// get the stiffness matrix AKANTU_GET_MACRO(StiffnessMatrix, *stiffness_matrix, SparseMatrix &); /// get the mass matrix AKANTU_GET_MACRO(MassMatrix, *mass_matrix, SparseMatrix &); __aka_inline__ FEM & getFEMBoundary(std::string name = ""); private: /// compute the stable time step Real getStableTimeStep(const GhostType & ghost_type); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: /// time step Real time_step; /// conversion coefficient form force/mass to acceleration Real f_m2a; /// displacements array Vector<Real> * displacement; /// lumped mass array Vector<Real> * mass; /// velocities array Vector<Real> * velocity; /// accelerations array Vector<Real> * acceleration; /// accelerations array Vector<Real> * increment_acceleration; /// forces array Vector<Real> * force; /// residuals array Vector<Real> * residual; /// boundaries array Vector<bool> * boundary; /// array of current position used during update residual Vector<Real> * current_position; /// mass matrix SparseMatrix * mass_matrix; /// velocity damping matrix SparseMatrix * velocity_damping_matrix; /// stiffness matrix SparseMatrix * stiffness_matrix; /// jacobian matrix @f[A = cM + dD + K@f] with @f[c = \frac{1}{\beta \Delta t^2}, d = \frac{\gamma}{\beta \Delta t} @f] SparseMatrix * jacobian_matrix; /// materials of all elements ByElementTypeUInt element_material; /// list of used materials std::vector<Material *> materials; /// integration scheme of second order used IntegrationScheme2ndOrder * integrator; /// increment of displacement Vector<Real> * increment; /// flag defining if the increment must be computed or not bool increment_flag; /// solver for implicit Solver * solver; /// object to resolve the contact Contact * contact; /// the spatial dimension UInt spatial_dimension; /// Mesh Mesh & mesh; bool dynamic; bool implicit; }; __END_AKANTU__ /* -------------------------------------------------------------------------- */ /* __aka_inline__ functions */ /* -------------------------------------------------------------------------- */ #include "parser.hh" __BEGIN_AKANTU__ #include "solid_mechanics_model_tmpl.hh" #if defined (AKANTU_INCLUDE_INLINE_IMPL) # include "solid_mechanics_model_inline_impl.cc" #endif /// standard output stream operator inline std::ostream & operator <<(std::ostream & stream, const SolidMechanicsModel & _this) { _this.printself(stream); return stream; } __END_AKANTU__ #endif /* __AKANTU_SOLID_MECHANICS_MODEL_HH__ */ diff --git a/src/synchronizer/real_static_communicator.hh b/src/synchronizer/real_static_communicator.hh index c85cb99b2..09a62f447 100644 --- a/src/synchronizer/real_static_communicator.hh +++ b/src/synchronizer/real_static_communicator.hh @@ -1,93 +1,93 @@ /** * @file real_static_communicator.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Apr 7 12:19:34 2011 * * @brief empty class just for inheritance * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_REAL_STATIC_COMMUNICATOR_HH__ #define __AKANTU_REAL_STATIC_COMMUNICATOR_HH__ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ class CommunicationRequest { public: CommunicationRequest(UInt source, UInt dest); virtual ~CommunicationRequest(); virtual void printself(std::ostream & stream, int indent = 0) const; AKANTU_GET_MACRO(Source, source, UInt); AKANTU_GET_MACRO(Destination, destination, UInt); private: UInt source; UInt destination; UInt id; static UInt counter; }; /* -------------------------------------------------------------------------- */ class CommunicationStatus { public: AKANTU_GET_MACRO(Source, source, Int); AKANTU_GET_MACRO(Size, size, UInt); AKANTU_GET_MACRO(Tag, tag, Int); AKANTU_SET_MACRO(Source, source, Int); AKANTU_SET_MACRO(Size, size, UInt); AKANTU_SET_MACRO(Tag, tag, Int); private: Int source; UInt size; Int tag; }; class StaticCommunicator; /* -------------------------------------------------------------------------- */ class RealStaticCommunicator { public: - RealStaticCommunicator(__attribute__ ((unused)) int * argc, - __attribute__ ((unused)) char *** argv) { + RealStaticCommunicator(__attribute__ ((unused)) int & argc, + __attribute__ ((unused)) char ** & argv) { prank = -1; psize = -1; }; virtual ~RealStaticCommunicator() { }; friend class StaticCommunicator; protected: Int prank; Int psize; }; __END_AKANTU__ #endif /* __AKANTU_REAL_STATIC_COMMUNICATOR_HH__ */ diff --git a/src/synchronizer/static_communicator.cc b/src/synchronizer/static_communicator.cc index 3976f5112..996f0541b 100644 --- a/src/synchronizer/static_communicator.cc +++ b/src/synchronizer/static_communicator.cc @@ -1,115 +1,117 @@ /** * @file static_communicator.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Aug 19 15:39:47 2010 * * @brief implementation of the common part of the static communicator * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "static_communicator.hh" #include "static_communicator_dummy.hh" #ifdef AKANTU_USE_MPI # include "static_communicator_mpi.hh" #endif /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ bool StaticCommunicator::is_instantiated = false; StaticCommunicator * StaticCommunicator::static_communicator = NULL; UInt CommunicationRequest::counter = 0; /* -------------------------------------------------------------------------- */ CommunicationRequest::CommunicationRequest(UInt source, UInt dest) : source(source), destination(dest) { this->id = counter++; } /* -------------------------------------------------------------------------- */ CommunicationRequest::~CommunicationRequest() { } /* -------------------------------------------------------------------------- */ void CommunicationRequest::printself(std::ostream & stream, int indent) const { std::string space; for(Int i = 0; i < indent; i++, space += AKANTU_INDENT); stream << space << "CommunicationRequest [" << std::endl; stream << space << " + id : " << id << std::endl; stream << space << " + source : " << source << std::endl; stream << space << " + destination : " << destination << std::endl; stream << space << "]" << std::endl; } /* -------------------------------------------------------------------------- */ -StaticCommunicator::StaticCommunicator(int * argc, - char *** argv, +StaticCommunicator::StaticCommunicator(int & argc, + char ** & argv, CommunicatorType type) { real_type = type; #ifdef AKANTU_USE_MPI if(type == _communicator_mpi) { real_static_communicator = new StaticCommunicatorMPI(argc, argv); } else { #endif real_static_communicator = new StaticCommunicatorDummy(argc, argv); #ifdef AKANTU_USE_MPI } #endif } /* -------------------------------------------------------------------------- */ StaticCommunicator * StaticCommunicator::getStaticCommunicator(CommunicatorType type) { AKANTU_DEBUG_IN(); if (!static_communicator) { #ifdef AKANTU_USE_MPI if(type == _communicator_mpi) { AKANTU_DEBUG_ERROR("You must call getStaticCommunicator(argc, argv) to create a MPI communicator"); } #endif - static_communicator = new StaticCommunicator(0, NULL, type); + int nb_args = 0; + char ** null; + static_communicator = new StaticCommunicator(nb_args, null, type); } is_instantiated = true; AKANTU_DEBUG_OUT(); return static_communicator; } /* -------------------------------------------------------------------------- */ -StaticCommunicator * StaticCommunicator::getStaticCommunicator(int * argc, - char *** argv, +StaticCommunicator * StaticCommunicator::getStaticCommunicator(int & argc, + char ** & argv, CommunicatorType type) { if (!static_communicator) static_communicator = new StaticCommunicator(argc, argv, type); return getStaticCommunicator(type); } __END_AKANTU__ diff --git a/src/synchronizer/static_communicator.hh b/src/synchronizer/static_communicator.hh index 7636fdf08..7f419090c 100644 --- a/src/synchronizer/static_communicator.hh +++ b/src/synchronizer/static_communicator.hh @@ -1,175 +1,175 @@ /** * @file static_communicator.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Aug 19 15:34:09 2010 * * @brief Class handling the parallel communications * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_STATIC_COMMUNICATOR_HH__ #define __AKANTU_STATIC_COMMUNICATOR_HH__ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #define AKANTU_COMMUNICATOR_LIST_0 BOOST_PP_SEQ_NIL #include "static_communicator_dummy.hh" #define AKANTU_COMMUNICATOR_LIST_1 \ BOOST_PP_SEQ_PUSH_BACK(AKANTU_COMMUNICATOR_LIST_0, \ (_communicator_dummy, (StaticCommunicatorDummy, BOOST_PP_NIL))) #if defined(AKANTU_USE_MPI) # include "static_communicator_mpi.hh" # define AKANTU_COMMUNICATOR_LIST_ALL \ BOOST_PP_SEQ_PUSH_BACK(AKANTU_COMMUNICATOR_LIST_1, \ (_communicator_mpi, (StaticCommunicatorMPI, BOOST_PP_NIL))) #else # define AKANTU_COMMUNICATOR_LIST_ALL AKANTU_COMMUNICATOR_LIST_1 #endif // AKANTU_COMMUNICATOR_LIST #include "real_static_communicator.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ class RealStaticCommunicator; class StaticCommunicator { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ protected: - StaticCommunicator(int * arc, char *** argv, + StaticCommunicator(int & argc, char ** & argv, CommunicatorType type = _communicator_mpi); public: virtual ~StaticCommunicator() { delete real_static_communicator; }; /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /* ------------------------------------------------------------------------ */ /* Point to Point */ /* ------------------------------------------------------------------------ */ template<typename T> inline void send(T * buffer, Int size, Int receiver, Int tag); template<typename T> inline void receive(T * buffer, Int size, Int sender, Int tag); template<typename T> inline CommunicationRequest * asyncSend(T * buffer, Int size, Int receiver, Int tag); template<typename T> inline CommunicationRequest * asyncReceive(T * buffer, Int size, Int sender, Int tag); template<typename T> inline void probe(Int sender, Int tag, CommunicationStatus & status); /* ------------------------------------------------------------------------ */ /* Collectives */ /* ------------------------------------------------------------------------ */ template<typename T> inline void allReduce(T * values, Int nb_values, const SynchronizerOperation & op); template<typename T> inline void allGather(T * values, Int nb_values); template<typename T> inline void allGatherV(T * values, Int * nb_values); template<typename T> inline void gather(T * values, Int nb_values, Int root = 0); template<typename T> inline void gatherV(T * values, Int * nb_values, Int root = 0); template<typename T> inline void broadcast(T * values, Int nb_values, Int root = 0); inline void barrier(); /* ------------------------------------------------------------------------ */ /* Request handling */ /* ------------------------------------------------------------------------ */ inline bool testRequest(CommunicationRequest * request); inline void wait(CommunicationRequest * request); inline void waitAll(std::vector<CommunicationRequest *> & requests); inline void freeCommunicationRequest(CommunicationRequest * request); inline void freeCommunicationRequest(std::vector<CommunicationRequest *> & requests); /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: virtual Int getNbProc() const { return real_static_communicator->psize; }; virtual Int whoAmI() const { return real_static_communicator->prank; }; AKANTU_GET_MACRO(RealStaticCommunicator, *real_static_communicator, const RealStaticCommunicator &); static StaticCommunicator * getStaticCommunicator(CommunicatorType type = _communicator_mpi); - static StaticCommunicator * getStaticCommunicator(int * argc, char *** argv, + static StaticCommunicator * getStaticCommunicator(int & argc, char ** & argv, CommunicatorType type = _communicator_mpi); static bool isInstantiated() { return is_instantiated; }; /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: static bool is_instantiated; static StaticCommunicator * static_communicator; RealStaticCommunicator * real_static_communicator; CommunicatorType real_type; }; /* -------------------------------------------------------------------------- */ /* inline functions */ /* -------------------------------------------------------------------------- */ #include "static_communicator_inline_impl.hh" /* -------------------------------------------------------------------------- */ /* Inline Functions VectorBase */ /* -------------------------------------------------------------------------- */ inline std::ostream & operator<<(std::ostream & stream, const CommunicationRequest & _this) { _this.printself(stream); return stream; } __END_AKANTU__ #endif /* __AKANTU_STATIC_COMMUNICATOR_HH__ */ diff --git a/src/synchronizer/static_communicator_dummy.hh b/src/synchronizer/static_communicator_dummy.hh index ced926074..d7e559cb3 100644 --- a/src/synchronizer/static_communicator_dummy.hh +++ b/src/synchronizer/static_communicator_dummy.hh @@ -1,141 +1,141 @@ /** * @file static_communicator_dummy.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Aug 19 15:34:09 2010 * * @brief Class handling the parallel communications * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_STATIC_COMMUNICATOR_DUMMY_HH__ #define __AKANTU_STATIC_COMMUNICATOR_DUMMY_HH__ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "real_static_communicator.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ class StaticCommunicatorDummy : public RealStaticCommunicator { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: - StaticCommunicatorDummy(__attribute__ ((unused)) int * argc, - __attribute__ ((unused)) char *** argv) : RealStaticCommunicator(argc, argv) { + StaticCommunicatorDummy(__attribute__ ((unused)) int & argc, + __attribute__ ((unused)) char ** & argv) : RealStaticCommunicator(argc, argv) { prank = 0; psize = 1; }; virtual ~StaticCommunicatorDummy() {}; /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: template<typename T> void send(__attribute__ ((unused)) T * buffer, __attribute__ ((unused)) Int size, __attribute__ ((unused)) Int receiver, __attribute__ ((unused)) Int tag) {} template<typename T> void receive(__attribute__ ((unused)) T * buffer, __attribute__ ((unused)) Int size, __attribute__ ((unused)) Int sender, __attribute__ ((unused)) Int tag) {} template<typename T> CommunicationRequest * asyncSend(__attribute__ ((unused)) T * buffer, __attribute__ ((unused)) Int size, __attribute__ ((unused)) Int receiver, __attribute__ ((unused)) Int tag) { return new CommunicationRequest(0, 0); } template<typename T> CommunicationRequest * asyncReceive(__attribute__ ((unused)) T * buffer, __attribute__ ((unused)) Int size, __attribute__ ((unused)) Int sender, __attribute__ ((unused)) Int tag) { return new CommunicationRequest(0, 0); } template<typename T> inline void probe(Int sender, Int tag, CommunicationStatus & status) { } bool testRequest(__attribute__ ((unused)) CommunicationRequest * request) { return true; }; void wait(__attribute__ ((unused)) CommunicationRequest * request) {}; void waitAll(__attribute__ ((unused)) std::vector<CommunicationRequest *> & requests) {}; void barrier() {}; template<typename T> void allReduce(__attribute__ ((unused)) T * values, __attribute__ ((unused)) Int nb_values, __attribute__ ((unused)) const SynchronizerOperation & op) {} template<typename T> __aka_inline__ void allGather(__attribute__ ((unused)) T * values, __attribute__ ((unused)) Int nb_values) {} template<typename T> __aka_inline__ void allGatherV(__attribute__ ((unused)) T * values, __attribute__ ((unused)) Int * nb_values) {} template<typename T> __aka_inline__ void gather(__attribute__ ((unused)) T * values, __attribute__ ((unused)) Int nb_values, __attribute__ ((unused)) Int root = 0) {} template<typename T> __aka_inline__ void gatherV(__attribute__ ((unused)) T * values, __attribute__ ((unused)) Int * nb_values, __attribute__ ((unused)) Int root = 0) {} template<typename T> __aka_inline__ void broadcast(__attribute__ ((unused)) T * values, __attribute__ ((unused)) Int nb_values, __attribute__ ((unused)) Int root = 0) {} /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ }; __END_AKANTU__ #endif /* __AKANTU_STATIC_COMMUNICATOR_DUMMY_HH__ */ diff --git a/src/synchronizer/static_communicator_mpi.hh b/src/synchronizer/static_communicator_mpi.hh index 493d93b51..52e176702 100644 --- a/src/synchronizer/static_communicator_mpi.hh +++ b/src/synchronizer/static_communicator_mpi.hh @@ -1,129 +1,129 @@ /** * @file static_communicator_mpi.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Sep 2 19:59:58 2010 * * @brief class handling parallel communication trough MPI * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_STATIC_COMMUNICATOR_MPI_HH__ #define __AKANTU_STATIC_COMMUNICATOR_MPI_HH__ /* -------------------------------------------------------------------------- */ #include <mpi.h> /* -------------------------------------------------------------------------- */ #include "real_static_communicator.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ class CommunicationRequestMPI : public CommunicationRequest { public: inline CommunicationRequestMPI(UInt source, UInt dest); inline ~CommunicationRequestMPI(); inline MPI_Request * getMPIRequest() { return request; }; private: MPI_Request * request; }; /* -------------------------------------------------------------------------- */ class StaticCommunicatorMPI : public RealStaticCommunicator { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: - inline StaticCommunicatorMPI(int * argc, char *** argv); + inline StaticCommunicatorMPI(int & argc, char ** & argv); inline virtual ~StaticCommunicatorMPI(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: template<typename T> inline void send(T * buffer, Int size, Int receiver, Int tag); template<typename T> inline void receive(T * buffer, Int size, Int sender, Int tag); template<typename T> inline CommunicationRequest * asyncSend(T * buffer, Int size, Int receiver, Int tag); template<typename T> inline CommunicationRequest * asyncReceive(T * buffer, Int size, Int sender, Int tag); template<typename T> inline void probe(Int sender, Int tag, CommunicationStatus & status); template<typename T> inline void allGather(T * values, Int nb_values); template<typename T> inline void allGatherV(T * values, Int * nb_values); template<typename T> inline void gather(T * values, Int nb_values, Int root); template<typename T> inline void gatherV(T * values, Int * nb_values, Int root); template<typename T> inline void broadcast(T * values, Int nb_values, Int root); inline bool testRequest(CommunicationRequest * request); inline void wait(CommunicationRequest * request); inline void waitAll(std::vector<CommunicationRequest *> & requests); inline void barrier(); template<typename T> inline void allReduce(T * values, Int nb_values, const SynchronizerOperation & op); private: template<typename T> inline MPI_Datatype getMPIDatatype(); /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: inline void setMPICommunicator(MPI_Comm comm); inline MPI_Comm getMPICommunicator() const; /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: MPI_Comm communicator; static MPI_Op synchronizer_operation_to_mpi_op[_so_null + 1]; }; /* -------------------------------------------------------------------------- */ /* inline functions */ /* -------------------------------------------------------------------------- */ #include "static_communicator_mpi_inline_impl.hh" __END_AKANTU__ #endif /* __AKANTU_STATIC_COMMUNICATOR_MPI_HH__ */ diff --git a/src/synchronizer/static_communicator_mpi_inline_impl.hh b/src/synchronizer/static_communicator_mpi_inline_impl.hh index a2cb82253..5f4df9a16 100644 --- a/src/synchronizer/static_communicator_mpi_inline_impl.hh +++ b/src/synchronizer/static_communicator_mpi_inline_impl.hh @@ -1,334 +1,334 @@ /** * @file static_communicator_mpi_inline_impl.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Sep 2 15:10:51 2010 * * @brief implementation of the mpi communicator * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ inline CommunicationRequestMPI::CommunicationRequestMPI(UInt source, UInt dest) : CommunicationRequest(source, dest) { request = new MPI_Request; } /* -------------------------------------------------------------------------- */ inline CommunicationRequestMPI::~CommunicationRequestMPI() { delete request; } /* -------------------------------------------------------------------------- */ -inline StaticCommunicatorMPI::StaticCommunicatorMPI(int * argc, char *** argv) : +inline StaticCommunicatorMPI::StaticCommunicatorMPI(int & argc, char ** & argv) : RealStaticCommunicator(argc, argv) { - MPI_Init(argc, argv); + MPI_Init(&argc, &argv); setMPICommunicator(MPI_COMM_WORLD); } /* -------------------------------------------------------------------------- */ inline StaticCommunicatorMPI::~StaticCommunicatorMPI() { MPI_Finalize(); } /* -------------------------------------------------------------------------- */ inline void StaticCommunicatorMPI::setMPICommunicator(MPI_Comm comm) { communicator = comm; MPI_Comm_rank(communicator, &prank); MPI_Comm_size(communicator, &psize); } /* -------------------------------------------------------------------------- */ inline MPI_Comm StaticCommunicatorMPI::getMPICommunicator() const { return communicator; } /* -------------------------------------------------------------------------- */ template<typename T> inline void StaticCommunicatorMPI::send(T * buffer, Int size, Int receiver, Int tag) { MPI_Datatype type = getMPIDatatype<T>(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Send(buffer, size, type, receiver, tag, communicator); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Send."); } /* -------------------------------------------------------------------------- */ template<typename T> inline void StaticCommunicatorMPI::receive(T * buffer, Int size, Int sender, Int tag) { MPI_Status status; MPI_Datatype type = getMPIDatatype<T>(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Recv(buffer, size, type, sender, tag, communicator, &status); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Recv."); } /* -------------------------------------------------------------------------- */ template<typename T> inline CommunicationRequest * StaticCommunicatorMPI::asyncSend(T * buffer, Int size, Int receiver, Int tag) { CommunicationRequestMPI * request = new CommunicationRequestMPI(prank, receiver); MPI_Datatype type = getMPIDatatype<T>(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Isend(buffer, size, type, receiver, tag, communicator, request->getMPIRequest()); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Isend."); return request; } /* -------------------------------------------------------------------------- */ template<typename T> inline CommunicationRequest * StaticCommunicatorMPI::asyncReceive(T * buffer, Int size, Int sender, Int tag) { CommunicationRequestMPI * request = new CommunicationRequestMPI(sender, prank); MPI_Datatype type = getMPIDatatype<T>(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Irecv(buffer, size, type, sender, tag, communicator, request->getMPIRequest()); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Irecv."); return request; } /* -------------------------------------------------------------------------- */ template<typename T> inline void StaticCommunicatorMPI::probe(Int sender, Int tag, CommunicationStatus & status) { MPI_Status mpi_status; #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Probe(sender, tag, communicator, &mpi_status); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Probe."); MPI_Datatype type = getMPIDatatype<T>(); int count; MPI_Get_count(&mpi_status, type, &count); status.setSource(mpi_status.MPI_SOURCE); status.setTag(mpi_status.MPI_TAG); status.setSize(count); } /* -------------------------------------------------------------------------- */ inline bool StaticCommunicatorMPI::testRequest(CommunicationRequest * request) { MPI_Status status; int flag; CommunicationRequestMPI * req_mpi = static_cast<CommunicationRequestMPI *>(request); MPI_Request * req = req_mpi->getMPIRequest(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Test(req, &flag, &status); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Test."); return (flag != 0); } /* -------------------------------------------------------------------------- */ inline void StaticCommunicatorMPI::wait(CommunicationRequest * request) { MPI_Status status; CommunicationRequestMPI * req_mpi = static_cast<CommunicationRequestMPI *>(request); MPI_Request * req = req_mpi->getMPIRequest(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Wait(req, &status); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Wait."); } /* -------------------------------------------------------------------------- */ inline void StaticCommunicatorMPI::waitAll(std::vector<CommunicationRequest *> & requests) { MPI_Status status; std::vector<CommunicationRequest *>::iterator it; for(it = requests.begin(); it != requests.end(); ++it) { MPI_Request * req = static_cast<CommunicationRequestMPI *>(*it)->getMPIRequest(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Wait(req, &status); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Wait."); } } /* -------------------------------------------------------------------------- */ inline void StaticCommunicatorMPI::barrier() { MPI_Barrier(communicator); } /* -------------------------------------------------------------------------- */ template<typename T> inline void StaticCommunicatorMPI::allReduce(T * values, Int nb_values, const SynchronizerOperation & op) { MPI_Datatype type = getMPIDatatype<T>(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Allreduce(MPI_IN_PLACE, values, nb_values, type, synchronizer_operation_to_mpi_op[op], communicator); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Allreduce."); } /* -------------------------------------------------------------------------- */ template<typename T> inline void StaticCommunicatorMPI::allGather(T * values, Int nb_values) { MPI_Datatype type = getMPIDatatype<T>(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Allgather(MPI_IN_PLACE, nb_values, type, values, nb_values, type, communicator); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Allgather."); } /* -------------------------------------------------------------------------- */ template<typename T> inline void StaticCommunicatorMPI::allGatherV(T * values, Int * nb_values) { Int * displs = new Int[psize]; displs[0] = 0; for (Int i = 1; i < psize; ++i) { displs[i] = displs[i-1] + nb_values[i-1]; } MPI_Datatype type = getMPIDatatype<T>(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Allgatherv(MPI_IN_PLACE, *nb_values, type, values, nb_values, displs, type, communicator); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Gather."); delete [] displs; } /* -------------------------------------------------------------------------- */ template<typename T> inline void StaticCommunicatorMPI::gather(T * values, Int nb_values, Int root) { T * send_buf = NULL, * recv_buf = NULL; if(prank == root) { send_buf = (T *) MPI_IN_PLACE; recv_buf = values; } else { send_buf = values; } MPI_Datatype type = getMPIDatatype<T>(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Gather(send_buf, nb_values, type, recv_buf, nb_values, type, root, communicator); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Gather."); } /* -------------------------------------------------------------------------- */ template<typename T> inline void StaticCommunicatorMPI::gatherV(T * values, Int * nb_values, Int root) { Int * displs = NULL; if(prank == root) { displs = new Int[psize]; displs[0] = 0; for (Int i = 1; i < psize; ++i) { displs[i] = displs[i-1] + nb_values[i-1]; } } T * send_buf = NULL, * recv_buf = NULL; if(prank == root) { send_buf = (T *) MPI_IN_PLACE; recv_buf = values; } else send_buf = values; MPI_Datatype type = getMPIDatatype<T>(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Gatherv(send_buf, *nb_values, type, recv_buf, nb_values, displs, type, root, communicator); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Gather."); if(prank == root) { delete [] displs; } } /* -------------------------------------------------------------------------- */ template<typename T> inline void StaticCommunicatorMPI::broadcast(T * values, Int nb_values, Int root) { MPI_Datatype type = getMPIDatatype<T>(); #if !defined(AKANTU_NDEBUG) int ret = #endif MPI_Bcast(values, nb_values, type, root, communicator); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Gather."); } /* -------------------------------------------------------------------------- */ // template<typename T> // inline MPI_Datatype StaticCommunicatorMPI::getMPIDatatype() { // return MPI_DATATYPE_NULL; // } template<> inline MPI_Datatype StaticCommunicatorMPI::getMPIDatatype<char>() { return MPI_CHAR; } template<> inline MPI_Datatype StaticCommunicatorMPI::getMPIDatatype<Real>() { return MPI_DOUBLE; } template<> inline MPI_Datatype StaticCommunicatorMPI::getMPIDatatype<UInt>() { return MPI_UNSIGNED; } template<> inline MPI_Datatype StaticCommunicatorMPI::getMPIDatatype<Int>() { return MPI_INT; } /* -------------------------------------------------------------------------- */ diff --git a/test/test_fem/test_gradient.cc b/test/test_fem/test_gradient.cc index a46081508..469daac14 100644 --- a/test/test_fem/test_gradient.cc +++ b/test/test_fem/test_gradient.cc @@ -1,147 +1,147 @@ /** * @file test_gradient_XXXX.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Mon Jul 19 10:55:49 2010 * * @brief test of the fem class * * @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 <http://www.gnu.org/licenses/>. * * @section DESCRIPTION * * This code is computing the gradient of a linear field and check that it gives * a constant result. It also compute the gradient the coordinates of the mesh * and check that it gives the identity * */ /* -------------------------------------------------------------------------- */ #include <cstdlib> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "fem.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "shape_lagrange.hh" #include "integrator_gauss.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); debug::setDebugLevel(dblTest); const ElementType type = TYPE; UInt dim = ElementClass<type>::getSpatialDimension(); Real eps = 3e-13; std::cout << "Epsilon : " << eps << std::endl; MeshIOMSH mesh_io; Mesh my_mesh(dim); std::stringstream meshfilename; meshfilename << type << ".msh"; mesh_io.read(meshfilename.str(), my_mesh); FEM *fem = new FEMTemplate<IntegratorGauss,ShapeLagrange>(my_mesh, dim, "my_fem"); std::stringstream outfilename; outfilename << "out_" << type << ".txt"; std::ofstream my_file(outfilename.str().c_str()); fem->initShapeFunctions(); std::cout << *fem << std::endl; StaticMemory * st_mem = StaticMemory::getStaticMemory(); std::cout << *st_mem << std::endl; Real alpha[2][3] = {{13, 23, 31}, {11, 7, 5}}; /// create the 2 component field const Vector<Real> & position = fem->getMesh().getNodes(); Vector<Real> const_val(fem->getMesh().getNbNodes(), 2, "const_val"); UInt nb_element = my_mesh.getNbElement(type); UInt nb_quadrature_points = fem->getNbQuadraturePoints(type) * nb_element; Vector<Real> grad_on_quad(nb_quadrature_points, 2 * dim, "grad_on_quad"); for (UInt i = 0; i < const_val.getSize(); ++i) { const_val(i, 0) = 0; const_val(i, 1) = 0; for (UInt d = 0; d < dim; ++d) { const_val(i, 0) += alpha[0][d] * position(i, d); const_val(i, 1) += alpha[1][d] * position(i, d); } } /// compute the gradient fem->gradientOnQuadraturePoints(const_val, grad_on_quad, 2, type); my_file << const_val << std::endl; my_file << grad_on_quad << std::endl; std::cout << grad_on_quad << std::endl; /// check the results Vector<Real>::iterator<types::Matrix> it = grad_on_quad.begin(2,dim); Vector<Real>::iterator<types::Matrix> it_end = grad_on_quad.end(2,dim); for (;it != it_end; ++it) { for (UInt d = 0; d < dim; ++d) { if(!(std::abs((*it)(0, d) - alpha[0][d]) < eps) || !(std::abs((*it)(1, d) - alpha[1][d]) < eps)) { std::cout << "Error gradient is not correct " << (*it)(0, d) << " " << alpha[0][d] << " (" << std::abs((*it)(0, d) - alpha[0][d]) << ")" << " - " << (*it)(1, d) << " " << alpha[1][d] << " (" << std::abs((*it)(1, d) - alpha[1][d]) << ")" << " - " << d << std::endl; std::cout << *it << std::endl; exit(EXIT_FAILURE); } } } // compute gradient of coordinates Vector<Real> grad_coord_on_quad(nb_quadrature_points, dim * dim, "grad_coord_on_quad"); fem->gradientOnQuadraturePoints(my_mesh.getNodes(), grad_coord_on_quad, my_mesh.getSpatialDimension(), type); my_file << my_mesh.getNodes() << std::endl; my_file << grad_coord_on_quad << std::endl; Vector<Real>::iterator<types::Matrix> itp = grad_coord_on_quad.begin(dim, dim); Vector<Real>::iterator<types::Matrix> itp_end = grad_coord_on_quad.end(dim, dim); for (;itp != itp_end; ++itp) { for (UInt i = 0; i < dim; ++i) { for (UInt j = 0; j < dim; ++j) { if(!(std::abs((*itp)(i,j) - (i == j)) < eps)) { std::cout << *itp << std::endl; exit(EXIT_FAILURE); } } } } delete fem; finalize(); return EXIT_SUCCESS; } diff --git a/test/test_fem/test_integrate.cc b/test/test_fem/test_integrate.cc index aa81013e1..b9c555fac 100644 --- a/test/test_fem/test_integrate.cc +++ b/test/test_fem/test_integrate.cc @@ -1,111 +1,111 @@ /** * @file test_integrate_XXXX.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> * @date Mon Jul 19 10:55:49 2010 * * @brief test of the fem class * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <cstdlib> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "fem.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "shape_lagrange.hh" #include "integrator_gauss.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); debug::setDebugLevel(dblTest); const ElementType type = TYPE; UInt dim = ElementClass<type>::getSpatialDimension(); Real eps = 3e-13; std::cout << "Epsilon : " << eps << std::endl; MeshIOMSH mesh_io; Mesh my_mesh(dim); std::stringstream meshfilename; meshfilename << type << ".msh"; mesh_io.read(meshfilename.str(), my_mesh); FEM *fem = new FEMTemplate<IntegratorGauss,ShapeLagrange>(my_mesh, dim, "my_fem"); std::stringstream outfilename; outfilename << "out_" << type << ".txt"; std::ofstream my_file(outfilename.str().c_str()); fem->initShapeFunctions(); std::cout << *fem << std::endl; StaticMemory * st_mem = StaticMemory::getStaticMemory(); std::cout << *st_mem << std::endl; UInt nb_element = my_mesh.getNbElement(type); UInt nb_quadrature_points = fem->getNbQuadraturePoints(type) * nb_element; Vector<Real> const_val(fem->getMesh().getNbNodes(), 2, "const_val"); Vector<Real> val_on_quad(nb_quadrature_points, 2 , "val_on_quad"); for (UInt i = 0; i < const_val.getSize(); ++i) { const_val.values[i * 2 + 0] = 1.; const_val.values[i * 2 + 1] = 2.; } //interpolate function on quadrature points fem->interpolateOnQuadraturePoints(const_val, val_on_quad, 2, type); //integrate function on elements akantu::Vector<akantu::Real> int_val_on_elem(nb_element, 2, "int_val_on_elem"); fem->integrate(val_on_quad, int_val_on_elem, 2, type); // get global integration value Real value[2] = {0,0}; my_file << val_on_quad << std::endl << int_val_on_elem << std::endl; for (UInt i = 0; i < fem->getMesh().getNbElement(type); ++i) { value[0] += int_val_on_elem.values[2*i]; value[1] += int_val_on_elem.values[2*i+1]; } my_file << "integral on the mesh of 1 is " << value[0] << " and of 2 is " << value[1] << std::endl; delete fem; finalize(); if(!(std::abs(value[0] - 1.) < eps && std::abs(value[1] - 2.) < eps)) { std::cout << "|1 - " << value[0] << "| = " << std::abs(value[0] - 1.) << std::endl << "|2 - " << value[1] << "| = " << std::abs(value[1] - 2.) << std::endl; return EXIT_FAILURE; } return EXIT_SUCCESS; } diff --git a/test/test_fem/test_interpolate.cc b/test/test_fem/test_interpolate.cc index 43fa21993..5d33af5b0 100644 --- a/test/test_fem/test_interpolate.cc +++ b/test/test_fem/test_interpolate.cc @@ -1,103 +1,103 @@ /** * @file test_interpolate_XXXX.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Mon Jul 19 10:55:49 2010 * * @brief test of the fem class * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <cstdlib> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "fem.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "shape_lagrange.hh" #include "integrator_gauss.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); debug::setDebugLevel(dblTest); const ElementType type = TYPE; UInt dim = ElementClass<type>::getSpatialDimension(); Real eps = 3e-13; std::cout << "Epsilon : " << eps << std::endl; MeshIOMSH mesh_io; Mesh my_mesh(dim); std::stringstream meshfilename; meshfilename << type << ".msh"; mesh_io.read(meshfilename.str(), my_mesh); FEM *fem = new FEMTemplate<IntegratorGauss,ShapeLagrange>(my_mesh, dim, "my_fem"); //UInt nb_quadrature_points = FEM::getNbQuadraturePoints(type); std::stringstream outfilename; outfilename << "out_" << type << ".txt"; std::ofstream my_file(outfilename.str().c_str()); fem->initShapeFunctions(); std::cout << *fem << std::endl; StaticMemory * st_mem = StaticMemory::getStaticMemory(); std::cout << *st_mem << std::endl; Vector<Real> const_val(fem->getMesh().getNbNodes(), 2, "const_val"); UInt nb_element = my_mesh.getNbElement(type); UInt nb_quadrature_points = fem->getNbQuadraturePoints(type) * nb_element; Vector<Real> val_on_quad(nb_quadrature_points, 2, "val_on_quad"); for (UInt i = 0; i < const_val.getSize(); ++i) { const_val.values[i * 2 + 0] = 1.; const_val.values[i * 2 + 1] = 2.; } fem->interpolateOnQuadraturePoints(const_val, val_on_quad, 2, type); my_file << const_val << std::endl; my_file << val_on_quad << std::endl; // interpolate coordinates Vector<Real> coord_on_quad(nb_quadrature_points, my_mesh.getSpatialDimension(), "coord_on_quad"); fem->interpolateOnQuadraturePoints(my_mesh.getNodes(), coord_on_quad, my_mesh.getSpatialDimension(), type); my_file << my_mesh.getNodes() << std::endl; my_file << coord_on_quad << std::endl; delete fem; finalize(); return EXIT_SUCCESS; } diff --git a/test/test_mesh_utils/test_facet_extraction/test_facet_extraction_tetrahedron_4.cc b/test/test_mesh_utils/test_facet_extraction/test_facet_extraction_tetrahedron_4.cc index b9218acf3..47aab1fa0 100644 --- a/test/test_mesh_utils/test_facet_extraction/test_facet_extraction_tetrahedron_4.cc +++ b/test/test_mesh_utils/test_facet_extraction/test_facet_extraction_tetrahedron_4.cc @@ -1,88 +1,89 @@ /** * @file test_facet_extraction_tetra1.cc * @author Guillaume ANCIAUX <guillaume.anciaux@epfl.ch> * @date Thu Aug 19 13:05:27 2010 * * @brief test of internal facet extraction * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); int dim = 3; Mesh mesh(dim); MeshIOMSH mesh_io; mesh_io.read("cube.msh", mesh); MeshUtils::buildFacets(mesh,1,1); #ifdef AKANTU_USE_IOHELPER unsigned int nb_nodes = mesh.getNbNodes(); DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-facet-extraction"); dumper.SetConnectivity((int*)mesh.getConnectivity(_tetrahedron_4).values, TETRA1, mesh.getNbElement(_tetrahedron_4), C_MODE); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); DumperParaview dumper_facet; dumper_facet.SetMode(TEXT); dumper_facet.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-facet-extraction_boundary"); dumper_facet.SetConnectivity((int*)mesh.getConnectivity(_triangle_3).values, TRIANGLE1, mesh.getNbElement(_triangle_3), C_MODE); dumper_facet.SetPrefix("paraview/"); dumper_facet.Init(); dumper_facet.Dump(); dumper_facet.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-facet-extraction_internal"); dumper_facet.SetConnectivity((int*)mesh.getInternalFacetsMesh().getConnectivity(_triangle_3).values, TRIANGLE1, mesh.getInternalFacetsMesh().getNbElement(_triangle_3), C_MODE); dumper_facet.Init(); dumper_facet.Dump(); #endif //AKANTU_USE_IOHELPER akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_mesh_utils/test_facet_extraction/test_facet_extraction_triangle_3.cc b/test/test_mesh_utils/test_facet_extraction/test_facet_extraction_triangle_3.cc index 6ade9f887..36916b4e7 100644 --- a/test/test_mesh_utils/test_facet_extraction/test_facet_extraction_triangle_3.cc +++ b/test/test_mesh_utils/test_facet_extraction/test_facet_extraction_triangle_3.cc @@ -1,90 +1,91 @@ /** * @file test_facet_extraction.cc * @author Guillaume ANCIAUX <guillaume.anciaux@epfl.ch> * @date Thu Aug 19 13:05:27 2010 * * @brief test of internal facet extraction * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); const ElementType type = _triangle_3; int dim = ElementClass<type>::getSpatialDimension(); Mesh mesh(dim); MeshIOMSH mesh_io; mesh_io.read("square.msh", mesh); MeshUtils::buildFacets(mesh,1,1); #ifdef AKANTU_USE_IOHELPER const ElementType surf_type = ElementClass<type>::getFacetElementType(); unsigned int nb_nodes = mesh.getNbNodes(); DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-facet-extraction"); dumper.SetConnectivity((int*)mesh.getConnectivity(type).values, TRIANGLE1, mesh.getNbElement(type), C_MODE); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); DumperParaview dumper_facet; dumper_facet.SetMode(TEXT); dumper_facet.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-facet-extraction_boundary"); dumper_facet.SetConnectivity((int*)mesh.getConnectivity(surf_type).values, LINE1, mesh.getNbElement(surf_type), C_MODE); dumper_facet.SetPrefix("paraview/"); dumper_facet.Init(); dumper_facet.Dump(); dumper_facet.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-facet-extraction_internal"); dumper_facet.SetConnectivity((int*)mesh.getInternalFacetsMesh().getConnectivity(surf_type).values, LINE1, mesh.getInternalFacetsMesh().getNbElement(surf_type), C_MODE); dumper_facet.Init(); dumper_facet.Dump(); #endif //AKANTU_USE_IOHELPER akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_mesh_utils/test_mesh_io/test_mesh_io_diana.cc b/test/test_mesh_utils/test_mesh_io/test_mesh_io_diana.cc index ca48a4967..af73e447c 100644 --- a/test/test_mesh_utils/test_mesh_io/test_mesh_io_diana.cc +++ b/test/test_mesh_utils/test_mesh_io/test_mesh_io_diana.cc @@ -1,122 +1,122 @@ /** * @file test_mesh_io_diana.cc * @author Alodie Schneuwly <alodie.schneuwly@epfl.ch> * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Mar 10 16:08:22 2011 * * @brief test reading mesh diana * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include <cstdlib> #include <iostream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_diana.hh" #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" #endif //AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { int dim = 3; const ElementType element_type = _tetrahedron_4; const UInt paraview_type = TETRA1; akantu::MeshIODiana mesh_io; akantu::Mesh mesh(3); mesh_io.read("./dam.dat", mesh); std::cout << mesh << std::endl; UInt nb_nodes = mesh.getNbNodes(); UInt nb_elements = mesh.getNbElement(element_type); std::vector<std::string> node_groups = mesh_io.getNodeGroupsNames(); std::vector<std::string> element_groups = mesh_io.getElementGroupsNames(); #ifdef AKANTU_USE_IOHELPER /// initialize the paraview output DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(mesh.getNodes().values, dim, nb_nodes, "dam_diana"); dumper.SetConnectivity((int *)mesh.getConnectivity(element_type).values, paraview_type, nb_elements, C_MODE); UInt i = 0; Real * nodes_grps[node_groups.size()]; std::cout << "Nb node groups : " << node_groups.size() << std::endl; std::vector<std::string>::iterator it_nodes; for(it_nodes = node_groups.begin(); it_nodes != node_groups.end(); ++it_nodes) { nodes_grps[i] = new Real[nb_nodes]; std::fill_n(nodes_grps[i], 0, nb_nodes); const Vector<UInt> & group = mesh_io.getNodeGroup(*it_nodes); for (UInt n = 0; n < group.getSize(); ++n) { nodes_grps[i][group(n)] = 1.; } dumper.AddNodeDataField(nodes_grps[i], 1, (*it_nodes).c_str()); std::cout << " " << *it_nodes; i++; } std::cout << std::endl; i = 0; Real * elements_grps[element_groups.size()]; std::cout << "Nb element groups : " << element_groups.size() << std::endl; std::vector<std::string>::iterator it_elements; for(it_elements = element_groups.begin(); it_elements != element_groups.end(); ++it_elements) { elements_grps[i] = new Real[nb_elements]; std::fill_n(elements_grps[i], 0, nb_elements); const std::vector<Element> & group = mesh_io.getElementGroup(*it_elements); for (UInt n = 0; n < group.size(); ++n) { elements_grps[i][group[n].element] = 1.; } dumper.AddElemDataField(elements_grps[i], 1, (*it_elements).c_str()); std::cout << " " << *it_elements; i++; } std::cout << std::endl; dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER return EXIT_SUCCESS; } diff --git a/test/test_mesh_utils/test_mesh_io/test_mesh_io_msh.cc b/test/test_mesh_utils/test_mesh_io/test_mesh_io_msh.cc index f3b2aa37c..9c30442f3 100644 --- a/test/test_mesh_utils/test_mesh_io/test_mesh_io_msh.cc +++ b/test/test_mesh_utils/test_mesh_io/test_mesh_io_msh.cc @@ -1,50 +1,50 @@ /** * @file test_mesh_io_msh.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Wed Jul 14 14:27:11 2010 * * @brief unit test for the MeshIOMSH class * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <cstdlib> /* -------------------------------------------------------------------------- */ #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); akantu::MeshIOMSH mesh_io; akantu::Mesh mesh(3); mesh_io.read("./cube.msh", mesh); std::cout << mesh << std::endl; akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_mesh_utils/test_mesh_partitionate/test_mesh_partitionate_scotch.cc b/test/test_mesh_utils/test_mesh_partitionate/test_mesh_partitionate_scotch.cc index 0b195e6fc..11ea44631 100644 --- a/test/test_mesh_utils/test_mesh_partitionate/test_mesh_partitionate_scotch.cc +++ b/test/test_mesh_utils/test_mesh_partitionate/test_mesh_partitionate_scotch.cc @@ -1,96 +1,97 @@ /** * @file test_mesh_partitionate_scotch.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Aug 19 13:05:27 2010 * * @brief test of internal facet extraction * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "fem.hh" #include "mesh_io_msh.hh" #include "mesh_partition_scotch.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ /* Main */ /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::debug::setDebugLevel(akantu::dblDump); int dim = 2; #ifdef AKANTU_USE_IOHELPER akantu::ElementType type = akantu::_triangle_6; #endif //AKANTU_USE_IOHELPER akantu::Mesh mesh(dim); akantu::MeshIOMSH mesh_io; mesh_io.read("triangle.msh", mesh); akantu::MeshPartition * partition = new akantu::MeshPartitionScotch(mesh, dim); partition->partitionate(8); #ifdef AKANTU_USE_IOHELPER unsigned int nb_nodes = mesh.getNbNodes(); unsigned int nb_element = mesh.getNbElement(type); DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-scotch-partition"); dumper.SetConnectivity((int*) mesh.getConnectivity(type).values, TRIANGLE2, nb_element, C_MODE); akantu::UInt nb_quadrature_points = 3; double * part = new double[nb_element*nb_quadrature_points]; akantu::UInt * part_val = partition->getPartition(type).values; for (unsigned int i = 0; i < nb_element; ++i) for (unsigned int q = 0; q < nb_quadrature_points; ++q) part[i*nb_quadrature_points + q] = part_val[i]; dumper.AddElemDataField(part, 1, "partitions"); dumper.SetPrefix("paraview"); dumper.Init(); dumper.Dump(); delete [] part; #endif //AKANTU_USE_IOHELPER partition->reorder(); mesh_io.write("triangle_reorder.msh", mesh); delete partition; akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_mesh_utils/test_pbc_tweak/test_pbc_tweak.cc b/test/test_mesh_utils/test_pbc_tweak/test_pbc_tweak.cc index 63297a91a..d3c297a1c 100644 --- a/test/test_mesh_utils/test_pbc_tweak/test_pbc_tweak.cc +++ b/test/test_mesh_utils/test_pbc_tweak/test_pbc_tweak.cc @@ -1,92 +1,93 @@ /** * @file test_facet_extraction_tetra1.cc * @author Guillaume ANCIAUX <guillaume.anciaux@epfl.ch> * @date Thu Aug 19 13:05:27 2010 * * @brief test of internal facet extraction * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "pbc_synchronizer.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { int dim = 3; - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::debug::setDebugLevel(akantu::dblInfo); Mesh mesh(dim); MeshIOMSH mesh_io; mesh_io.read("cube.msh", mesh); SolidMechanicsModel * model = new SolidMechanicsModel(mesh); /* -------------------------------------------------------------------------- */ model->initVectors(); model->getForce().clear(); model->getVelocity().clear(); model->getAcceleration().clear(); model->getDisplacement().clear(); /* ------------------------------------------------------------------------ */ model->initExplicit(); model->initModel(); model->readMaterials("material.dat"); model->initMaterials(); /* -------------------------------------------------------------------------- */ model->initPBC(1,1,1); model->assembleMassLumped(); /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); dumper.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-pbc-tweak"); dumper.SetConnectivity((int*)mesh.getConnectivity(_hexahedron_8).values, HEX1, mesh.getNbElement(_hexahedron_8), C_MODE); dumper.AddNodeDataField(model->getMass().values, 3, "mass"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER return EXIT_SUCCESS; } diff --git a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_coarse_square_mesh.cc b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_coarse_square_mesh.cc index 2296ad673..46cb98b40 100644 --- a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_coarse_square_mesh.cc +++ b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_coarse_square_mesh.cc @@ -1,264 +1,264 @@ /** * @file test_heat_transfer_model_cube3d.cc * @author Rui WANG<rui.wang@epfl.ch> * @date Tue May 17 11:31:22 2011 * * @brief test of the class HeatTransferModel on the 3d cube * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "heat_transfer_model.hh" //#include "material.hh" // basic file operations #include <iostream> #include <fstream> #include <string.h> using namespace std; /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include "io_helper.h" +#include "io_helper.hh" #endif //AKANTU_USE_IOHELPER akantu::UInt spatial_dimension = 3; akantu:: ElementType type = akantu::_tetrahedron_4; akantu::UInt paraview_type = TETRA1; // akantu::UInt spatial_dimension = 3; // akantu:: ElementType type = akantu::_hexahedron_8; // akantu::UInt paraview_type = HEX1; // //just for checking // akantu::UInt spatial_dimension = 2; // akantu:: ElementType type = akantu::_triangle_3; // akantu::UInt paraview_type = TRIANGLE1; // akantu::UInt spatial_dimension = 2; // akantu:: ElementType type = akantu::_quadrangle_4; // akantu::UInt paraview_type = QUAD1; // akantu::UInt spatial_dimension = 1; // akantu:: ElementType type = akantu::_segment_2; // akantu::UInt paraview_type = LINE1; //just for checking void paraviewInit(Dumper & dumper); void paraviewDump(Dumper & dumper); akantu::HeatTransferModel * model; akantu::UInt nb_nodes; akantu::UInt nb_element; akantu::Real density; akantu::Real conductivity[3][3]; akantu::Real capacity; int readMaterial () { string str; ifstream myfile; myfile.open("material.dat"); if(!myfile) //Always test the file open. { cout<<"Error opening output file"<<endl; return -1; } getline(myfile, str); density=atof(str.c_str()); getline(myfile, str); capacity=atof(str.c_str()); getline(myfile, str); char * cstr, *p; char * tmp_cstr; cstr = new char [str.size()+1]; strcpy (cstr, str.c_str()); // p=strtok (cstr," "); // conductivity[0][0]= atof(p); // cout<<conductivity[0][0]<<endl; // p=strtok(NULL, " "); // conductivity[0][1]= atof(p); // cout<<conductivity[0][1]<<endl; // p=strtok(NULL, " "); // conductivity[0][2]= atof(p); // cout<<conductivity[0][2]<<endl; tmp_cstr = cstr; for(int i=0;i<3;i++) for(int j=0; j<3;j++) { p=strtok(tmp_cstr, " "); tmp_cstr = NULL; conductivity[i][j]= atof(p); cout<<conductivity[i][j]<<endl; } return 0; } int main(int argc, char *argv[]) { akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("cube1.msh", mesh); //just for checking // mesh_io.read("square1.msh", mesh); // mesh_io.read("bar1.msh", mesh); // mesh_io.read("line.msh", mesh); readMaterial(); cout<<"The density of the material is:"<< density <<endl; cout<<"The capacity of the material is:"<< capacity <<endl; model = new akantu::HeatTransferModel(mesh); //model initialization model->initModel(); //initialize the vectors model->initVectors(); nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_element = model->getFEM().getMesh().getNbElement(type); akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); model->getHeatFlux().clear(); model->getLumped().clear(); model->getTemperatureGradient(type).clear(); // akantu::debug::setDebugLevel(akantu::dblDump); // std::cout << model->getTemperatureGradient(type) << std::endl; // akantu::debug::setDebugLevel(akantu::dblWarning); model->setDensity(density); model->setCapacity(capacity); model->SetConductivityMatrix(conductivity); //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::Vector<akantu::Real> & nodes = model->getFEM().getMesh().getNodes(); akantu::Vector<bool> & boundary = model->getBoundary(); akantu::Vector<akantu::Real> & temperature = model->getTemperature(); akantu::Vector<akantu::Real> & heat_flux = model->getHeatFlux(); akantu::Real eps = 1e-15; double t1, t2, length; t1 = 300.; t2 = 100.; length = 1.; for (akantu::UInt i = 0; i < nb_nodes; ++i) { //temperature(i) = t1 - (t1 - t2) * sin(nodes(i, 0) * M_PI / length); temperature(i) = 100.; if(nodes(i,0) < eps) { boundary(i) = true; temperature(i) = 100.0; } //set the second boundary condition if(std::abs(nodes(i,0) - length) < eps) { boundary(i) = true; temperature(i) = 100.; } //to insert a heat source if(std::abs(nodes(i,0) - length/2.) < 0.025 && std::abs(nodes(i,1) - length/2.) < 0.025 && std::abs(nodes(i,2) - length/2.) < 0.025) { // if(std::abs(nodes(i,0) - length/2.) < 0.01 && std::abs(nodes(i,1) - length/2.) < 0.01) { boundary(i) = true; temperature(i) = 300.; } } DumperParaview dumper; paraviewInit(dumper); model->assembleMassLumped(type); // //for testing int max_steps = 100000; for(int i=0; i<max_steps; i++) { model->updateHeatFlux(); model->updateTemperature(); if(i % 100 == 0) paraviewDump(dumper); if(i % 10000 == 0) std::cout << "Step " << i << "/" << max_steps << std::endl; } cout<< "\n\n Stable Time Step is : " << time_step << "\n \n" <<endl; return 0; } void paraviewInit(Dumper & dumper) { dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates2"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getTemperature().values, 1, "temperature"); dumper.AddNodeDataField(model->getHeatFlux().values, 1, "heat_flux"); dumper.AddNodeDataField(model->getLumped().values, 1, "lumped"); dumper.AddElemDataField(model->getTemperatureGradient(type).values, spatial_dimension, "temperature_gradient"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } void paraviewDump(Dumper & dumper) { dumper.Dump(); } diff --git a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_coarse_triangle_mesh.cc b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_coarse_triangle_mesh.cc index 2296ad673..46cb98b40 100644 --- a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_coarse_triangle_mesh.cc +++ b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_coarse_triangle_mesh.cc @@ -1,264 +1,264 @@ /** * @file test_heat_transfer_model_cube3d.cc * @author Rui WANG<rui.wang@epfl.ch> * @date Tue May 17 11:31:22 2011 * * @brief test of the class HeatTransferModel on the 3d cube * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "heat_transfer_model.hh" //#include "material.hh" // basic file operations #include <iostream> #include <fstream> #include <string.h> using namespace std; /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include "io_helper.h" +#include "io_helper.hh" #endif //AKANTU_USE_IOHELPER akantu::UInt spatial_dimension = 3; akantu:: ElementType type = akantu::_tetrahedron_4; akantu::UInt paraview_type = TETRA1; // akantu::UInt spatial_dimension = 3; // akantu:: ElementType type = akantu::_hexahedron_8; // akantu::UInt paraview_type = HEX1; // //just for checking // akantu::UInt spatial_dimension = 2; // akantu:: ElementType type = akantu::_triangle_3; // akantu::UInt paraview_type = TRIANGLE1; // akantu::UInt spatial_dimension = 2; // akantu:: ElementType type = akantu::_quadrangle_4; // akantu::UInt paraview_type = QUAD1; // akantu::UInt spatial_dimension = 1; // akantu:: ElementType type = akantu::_segment_2; // akantu::UInt paraview_type = LINE1; //just for checking void paraviewInit(Dumper & dumper); void paraviewDump(Dumper & dumper); akantu::HeatTransferModel * model; akantu::UInt nb_nodes; akantu::UInt nb_element; akantu::Real density; akantu::Real conductivity[3][3]; akantu::Real capacity; int readMaterial () { string str; ifstream myfile; myfile.open("material.dat"); if(!myfile) //Always test the file open. { cout<<"Error opening output file"<<endl; return -1; } getline(myfile, str); density=atof(str.c_str()); getline(myfile, str); capacity=atof(str.c_str()); getline(myfile, str); char * cstr, *p; char * tmp_cstr; cstr = new char [str.size()+1]; strcpy (cstr, str.c_str()); // p=strtok (cstr," "); // conductivity[0][0]= atof(p); // cout<<conductivity[0][0]<<endl; // p=strtok(NULL, " "); // conductivity[0][1]= atof(p); // cout<<conductivity[0][1]<<endl; // p=strtok(NULL, " "); // conductivity[0][2]= atof(p); // cout<<conductivity[0][2]<<endl; tmp_cstr = cstr; for(int i=0;i<3;i++) for(int j=0; j<3;j++) { p=strtok(tmp_cstr, " "); tmp_cstr = NULL; conductivity[i][j]= atof(p); cout<<conductivity[i][j]<<endl; } return 0; } int main(int argc, char *argv[]) { akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("cube1.msh", mesh); //just for checking // mesh_io.read("square1.msh", mesh); // mesh_io.read("bar1.msh", mesh); // mesh_io.read("line.msh", mesh); readMaterial(); cout<<"The density of the material is:"<< density <<endl; cout<<"The capacity of the material is:"<< capacity <<endl; model = new akantu::HeatTransferModel(mesh); //model initialization model->initModel(); //initialize the vectors model->initVectors(); nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_element = model->getFEM().getMesh().getNbElement(type); akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); model->getHeatFlux().clear(); model->getLumped().clear(); model->getTemperatureGradient(type).clear(); // akantu::debug::setDebugLevel(akantu::dblDump); // std::cout << model->getTemperatureGradient(type) << std::endl; // akantu::debug::setDebugLevel(akantu::dblWarning); model->setDensity(density); model->setCapacity(capacity); model->SetConductivityMatrix(conductivity); //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::Vector<akantu::Real> & nodes = model->getFEM().getMesh().getNodes(); akantu::Vector<bool> & boundary = model->getBoundary(); akantu::Vector<akantu::Real> & temperature = model->getTemperature(); akantu::Vector<akantu::Real> & heat_flux = model->getHeatFlux(); akantu::Real eps = 1e-15; double t1, t2, length; t1 = 300.; t2 = 100.; length = 1.; for (akantu::UInt i = 0; i < nb_nodes; ++i) { //temperature(i) = t1 - (t1 - t2) * sin(nodes(i, 0) * M_PI / length); temperature(i) = 100.; if(nodes(i,0) < eps) { boundary(i) = true; temperature(i) = 100.0; } //set the second boundary condition if(std::abs(nodes(i,0) - length) < eps) { boundary(i) = true; temperature(i) = 100.; } //to insert a heat source if(std::abs(nodes(i,0) - length/2.) < 0.025 && std::abs(nodes(i,1) - length/2.) < 0.025 && std::abs(nodes(i,2) - length/2.) < 0.025) { // if(std::abs(nodes(i,0) - length/2.) < 0.01 && std::abs(nodes(i,1) - length/2.) < 0.01) { boundary(i) = true; temperature(i) = 300.; } } DumperParaview dumper; paraviewInit(dumper); model->assembleMassLumped(type); // //for testing int max_steps = 100000; for(int i=0; i<max_steps; i++) { model->updateHeatFlux(); model->updateTemperature(); if(i % 100 == 0) paraviewDump(dumper); if(i % 10000 == 0) std::cout << "Step " << i << "/" << max_steps << std::endl; } cout<< "\n\n Stable Time Step is : " << time_step << "\n \n" <<endl; return 0; } void paraviewInit(Dumper & dumper) { dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates2"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getTemperature().values, 1, "temperature"); dumper.AddNodeDataField(model->getHeatFlux().values, 1, "heat_flux"); dumper.AddNodeDataField(model->getLumped().values, 1, "lumped"); dumper.AddElemDataField(model->getTemperatureGradient(type).values, spatial_dimension, "temperature_gradient"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } void paraviewDump(Dumper & dumper) { dumper.Dump(); } diff --git a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_fine_square_mesh.cc b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_fine_square_mesh.cc index 636047421..d84b25f8b 100644 --- a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_fine_square_mesh.cc +++ b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_bar2d_fine_square_mesh.cc @@ -1,264 +1,264 @@ /** * @file test_heat_transfer_model_cube3d.cc * @author Rui WANG<rui.wang@epfl.ch> * @date Tue May 17 11:31:22 2011 * * @brief test of the class HeatTransferModel on the 3d cube * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "heat_transfer_model.hh" //#include "material.hh" // basic file operations #include <iostream> #include <fstream> #include <string.h> using namespace std; /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include "io_helper.h" +#include "io_helper.hh" #endif //AKANTU_USE_IOHELPER akantu::UInt spatial_dimension = 3; akantu:: ElementType type = akantu::_tetrahedron_4; akantu::UInt paraview_type = TETRA1; // akantu::UInt spatial_dimension = 3; // akantu:: ElementType type = akantu::_hexahedron_8; // akantu::UInt paraview_type = HEX1; // //just for checking // akantu::UInt spatial_dimension = 2; // akantu:: ElementType type = akantu::_triangle_3; // akantu::UInt paraview_type = TRIANGLE1; // akantu::UInt spatial_dimension = 2; // akantu:: ElementType type = akantu::_quadrangle_4; // akantu::UInt paraview_type = QUAD1; // akantu::UInt spatial_dimension = 1; // akantu:: ElementType type = akantu::_segment_2; // akantu::UInt paraview_type = LINE1; //just for checking void paraviewInit(Dumper & dumper); void paraviewDump(Dumper & dumper); akantu::HeatTransferModel * model; akantu::UInt nb_nodes; akantu::UInt nb_element; akantu::Real density; akantu::Real conductivity[3][3]; akantu::Real capacity; int readMaterial () { string str; ifstream myfile; myfile.open("Material.dat"); if(!myfile) //Always test the file open. { cout<<"Error opening output file"<<endl; return -1; } getline(myfile, str); density=atof(str.c_str()); getline(myfile, str); capacity=atof(str.c_str()); getline(myfile, str); char * cstr, *p; char * tmp_cstr; cstr = new char [str.size()+1]; strcpy (cstr, str.c_str()); // p=strtok (cstr," "); // conductivity[0][0]= atof(p); // cout<<conductivity[0][0]<<endl; // p=strtok(NULL, " "); // conductivity[0][1]= atof(p); // cout<<conductivity[0][1]<<endl; // p=strtok(NULL, " "); // conductivity[0][2]= atof(p); // cout<<conductivity[0][2]<<endl; tmp_cstr = cstr; for(int i=0;i<3;i++) for(int j=0; j<3;j++) { p=strtok(tmp_cstr, " "); tmp_cstr = NULL; conductivity[i][j]= atof(p); cout<<conductivity[i][j]<<endl; } return 0; } int main(int argc, char *argv[]) { akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("cube1.msh", mesh); //just for checking // mesh_io.read("square1.msh", mesh); // mesh_io.read("bar1.msh", mesh); // mesh_io.read("line.msh", mesh); readMaterial(); cout<<"The density of the material is:"<< density <<endl; cout<<"The capacity of the material is:"<< capacity <<endl; model = new akantu::HeatTransferModel(mesh); //model initialization model->initModel(); //initialize the vectors model->initVectors(); nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_element = model->getFEM().getMesh().getNbElement(type); akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); model->getHeatFlux().clear(); model->getLumped().clear(); model->getTemperatureGradient(type).clear(); // akantu::debug::setDebugLevel(akantu::dblDump); // std::cout << model->getTemperatureGradient(type) << std::endl; // akantu::debug::setDebugLevel(akantu::dblWarning); model->setDensity(density); model->setCapacity(capacity); model->SetConductivityMatrix(conductivity); //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::Vector<akantu::Real> & nodes = model->getFEM().getMesh().getNodes(); akantu::Vector<bool> & boundary = model->getBoundary(); akantu::Vector<akantu::Real> & temperature = model->getTemperature(); akantu::Vector<akantu::Real> & heat_flux = model->getHeatFlux(); akantu::Real eps = 1e-15; double t1, t2, length; t1 = 300.; t2 = 100.; length = 1.; for (akantu::UInt i = 0; i < nb_nodes; ++i) { //temperature(i) = t1 - (t1 - t2) * sin(nodes(i, 0) * M_PI / length); temperature(i) = 100.; if(nodes(i,0) < eps) { boundary(i) = true; temperature(i) = 100.0; } //set the second boundary condition if(std::abs(nodes(i,0) - length) < eps) { boundary(i) = true; temperature(i) = 100.; } //to insert a heat source if(std::abs(nodes(i,0) - length/2.) < 0.025 && std::abs(nodes(i,1) - length/2.) < 0.025 && std::abs(nodes(i,2) - length/2.) < 0.025) { // if(std::abs(nodes(i,0) - length/2.) < 0.01 && std::abs(nodes(i,1) - length/2.) < 0.01) { boundary(i) = true; temperature(i) = 300.; } } DumperParaview dumper; paraviewInit(dumper); model->assembleMassLumped(type); // //for testing int max_steps = 100000; for(int i=0; i<max_steps; i++) { model->updateHeatFlux(); model->updateTemperature(); if(i % 100 == 0) paraviewDump(dumper); if(i % 10000 == 0) std::cout << "Step " << i << "/" << max_steps << std::endl; } cout<< "\n\n Stable Time Step is : " << time_step << "\n \n" <<endl; return 0; } void paraviewInit(Dumper & dumper) { dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates2"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getTemperature().values, 1, "temperature"); dumper.AddNodeDataField(model->getHeatFlux().values, 1, "heat_flux"); dumper.AddNodeDataField(model->getLumped().values, 1, "lumped"); dumper.AddElemDataField(model->getTemperatureGradient(type).values, spatial_dimension, "temperature_gradient"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } void paraviewDump(Dumper & dumper) { dumper.Dump(); } diff --git a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d.cc b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d.cc index 02105635c..5711f111b 100644 --- a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d.cc +++ b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d.cc @@ -1,186 +1,187 @@ /** * @file test_heat_transfer_model_cube3d.cc * @author Rui WANG<rui.wang@epfl.ch> * @date Tue May 17 11:31:22 2011 * * @brief test of the class HeatTransferModel on the 3d cube * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <iostream> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "heat_transfer_model.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include "io_helper.h" +#include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER void paraviewInit(HeatTransferModel * model,Dumper & dumper); void paraviewDump(Dumper & dumper); -UInt paraview_type = TETRA1; +ElemType paraview_type = TETRA1; #endif UInt spatial_dimension = 3; ElementType type = _tetrahedron_4; /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - initialize(&argc,&argv); + initialize(argc, argv); Mesh mesh(spatial_dimension); MeshIOMSH mesh_io; mesh_io.read("cube1.msh", mesh); HeatTransferModel * model; UInt nb_nodes; UInt nb_element; model = new HeatTransferModel(mesh); model->readMaterials("material.dat"); //model initialization model->initModel(); //initialize the vectors model->initVectors(); nb_nodes = mesh.getNbNodes(); nb_element = mesh.getNbElement(type); nb_nodes = mesh.getNbNodes(); model->getTemperature().clear(); model->getTemperatureRate().clear(); //get stable time step Real time_step = model->getStableTimeStep()*0.8; std::cout << "time step is:" << time_step << std::endl; model->setTimeStep(time_step); /// boundary conditions const Vector<Real> & nodes = mesh.getNodes(); Vector<bool> & boundary = model->getBoundary(); Vector<Real> & temperature = model->getTemperature(); double t1, t2, length; t1 = 300.; t2 = 100.; length = 1.; for (UInt i = 0; i < nb_nodes; ++i) { //temperature(i) = t1 - (t1 - t2) * sin(nodes(i, 0) * M_PI / length); temperature(i) = 100.; // if(nodes(i,0) < eps) { // boundary(i) = true; // temperature(i) = 100.0; // } //set the second boundary condition // if(std::abs(nodes(i,0) - length) < eps) { // boundary(i) = true; // temperature(i) = 100.; // } //to insert a heat source Real dx = nodes(i,0) - length/2.; Real dy = nodes(i,1) - length/2.; Real dz = nodes(i,2) - length/2.; Real d = sqrt(dx*dx + dy*dy + dz*dz); if(d < 0.1){ boundary(i) = true; temperature(i) = 300.; } } #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(model,dumper); model->assembleCapacityLumped(); #endif // //for testing int max_steps = 1000; for(int i=0; i<max_steps; i++) { model->explicitPred(); model->updateResidual(); model->solveExplicitLumped(); model->explicitCorr(); #ifdef AKANTU_USE_IOHELPER if(i % 100 == 0) paraviewDump(dumper); #endif if(i % 10 == 0) std::cout << "Step " << i << "/" << max_steps << std::endl; } std::cout << "Stable Time Step is : " << time_step << std::endl; return 0; } /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER void paraviewInit(HeatTransferModel * model, Dumper & dumper) { Mesh & mesh = model->getFEM().getMesh(); UInt nb_nodes = mesh.getNbNodes(); UInt nb_element = mesh.getNbElement(type); dumper.SetMode(TEXT); dumper.SetPoints(mesh.getNodes().values, spatial_dimension, nb_nodes, "coordinates2"); dumper.SetConnectivity((int *) mesh.getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getTemperature().values, 1, "temperature"); dumper.AddNodeDataField(model->getTemperatureRate().values, 1, "temperature_rate"); dumper.AddNodeDataField(model->getResidual().values, 1, "residual"); dumper.AddNodeDataField(model->getCapacityLumped().values, 1, "capacity_lumped"); dumper.AddElemDataField(model->getTemperatureGradient(type).values, spatial_dimension, "temperature_gradient"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } #endif /* -------------------------------------------------------------------------- */ diff --git a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_anisotropy_conductivity.cc b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_anisotropy_conductivity.cc index 2296ad673..46cb98b40 100644 --- a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_anisotropy_conductivity.cc +++ b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_anisotropy_conductivity.cc @@ -1,264 +1,264 @@ /** * @file test_heat_transfer_model_cube3d.cc * @author Rui WANG<rui.wang@epfl.ch> * @date Tue May 17 11:31:22 2011 * * @brief test of the class HeatTransferModel on the 3d cube * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "heat_transfer_model.hh" //#include "material.hh" // basic file operations #include <iostream> #include <fstream> #include <string.h> using namespace std; /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include "io_helper.h" +#include "io_helper.hh" #endif //AKANTU_USE_IOHELPER akantu::UInt spatial_dimension = 3; akantu:: ElementType type = akantu::_tetrahedron_4; akantu::UInt paraview_type = TETRA1; // akantu::UInt spatial_dimension = 3; // akantu:: ElementType type = akantu::_hexahedron_8; // akantu::UInt paraview_type = HEX1; // //just for checking // akantu::UInt spatial_dimension = 2; // akantu:: ElementType type = akantu::_triangle_3; // akantu::UInt paraview_type = TRIANGLE1; // akantu::UInt spatial_dimension = 2; // akantu:: ElementType type = akantu::_quadrangle_4; // akantu::UInt paraview_type = QUAD1; // akantu::UInt spatial_dimension = 1; // akantu:: ElementType type = akantu::_segment_2; // akantu::UInt paraview_type = LINE1; //just for checking void paraviewInit(Dumper & dumper); void paraviewDump(Dumper & dumper); akantu::HeatTransferModel * model; akantu::UInt nb_nodes; akantu::UInt nb_element; akantu::Real density; akantu::Real conductivity[3][3]; akantu::Real capacity; int readMaterial () { string str; ifstream myfile; myfile.open("material.dat"); if(!myfile) //Always test the file open. { cout<<"Error opening output file"<<endl; return -1; } getline(myfile, str); density=atof(str.c_str()); getline(myfile, str); capacity=atof(str.c_str()); getline(myfile, str); char * cstr, *p; char * tmp_cstr; cstr = new char [str.size()+1]; strcpy (cstr, str.c_str()); // p=strtok (cstr," "); // conductivity[0][0]= atof(p); // cout<<conductivity[0][0]<<endl; // p=strtok(NULL, " "); // conductivity[0][1]= atof(p); // cout<<conductivity[0][1]<<endl; // p=strtok(NULL, " "); // conductivity[0][2]= atof(p); // cout<<conductivity[0][2]<<endl; tmp_cstr = cstr; for(int i=0;i<3;i++) for(int j=0; j<3;j++) { p=strtok(tmp_cstr, " "); tmp_cstr = NULL; conductivity[i][j]= atof(p); cout<<conductivity[i][j]<<endl; } return 0; } int main(int argc, char *argv[]) { akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("cube1.msh", mesh); //just for checking // mesh_io.read("square1.msh", mesh); // mesh_io.read("bar1.msh", mesh); // mesh_io.read("line.msh", mesh); readMaterial(); cout<<"The density of the material is:"<< density <<endl; cout<<"The capacity of the material is:"<< capacity <<endl; model = new akantu::HeatTransferModel(mesh); //model initialization model->initModel(); //initialize the vectors model->initVectors(); nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_element = model->getFEM().getMesh().getNbElement(type); akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); model->getHeatFlux().clear(); model->getLumped().clear(); model->getTemperatureGradient(type).clear(); // akantu::debug::setDebugLevel(akantu::dblDump); // std::cout << model->getTemperatureGradient(type) << std::endl; // akantu::debug::setDebugLevel(akantu::dblWarning); model->setDensity(density); model->setCapacity(capacity); model->SetConductivityMatrix(conductivity); //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::Vector<akantu::Real> & nodes = model->getFEM().getMesh().getNodes(); akantu::Vector<bool> & boundary = model->getBoundary(); akantu::Vector<akantu::Real> & temperature = model->getTemperature(); akantu::Vector<akantu::Real> & heat_flux = model->getHeatFlux(); akantu::Real eps = 1e-15; double t1, t2, length; t1 = 300.; t2 = 100.; length = 1.; for (akantu::UInt i = 0; i < nb_nodes; ++i) { //temperature(i) = t1 - (t1 - t2) * sin(nodes(i, 0) * M_PI / length); temperature(i) = 100.; if(nodes(i,0) < eps) { boundary(i) = true; temperature(i) = 100.0; } //set the second boundary condition if(std::abs(nodes(i,0) - length) < eps) { boundary(i) = true; temperature(i) = 100.; } //to insert a heat source if(std::abs(nodes(i,0) - length/2.) < 0.025 && std::abs(nodes(i,1) - length/2.) < 0.025 && std::abs(nodes(i,2) - length/2.) < 0.025) { // if(std::abs(nodes(i,0) - length/2.) < 0.01 && std::abs(nodes(i,1) - length/2.) < 0.01) { boundary(i) = true; temperature(i) = 300.; } } DumperParaview dumper; paraviewInit(dumper); model->assembleMassLumped(type); // //for testing int max_steps = 100000; for(int i=0; i<max_steps; i++) { model->updateHeatFlux(); model->updateTemperature(); if(i % 100 == 0) paraviewDump(dumper); if(i % 10000 == 0) std::cout << "Step " << i << "/" << max_steps << std::endl; } cout<< "\n\n Stable Time Step is : " << time_step << "\n \n" <<endl; return 0; } void paraviewInit(Dumper & dumper) { dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates2"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getTemperature().values, 1, "temperature"); dumper.AddNodeDataField(model->getHeatFlux().values, 1, "heat_flux"); dumper.AddNodeDataField(model->getLumped().values, 1, "lumped"); dumper.AddElemDataField(model->getTemperatureGradient(type).values, spatial_dimension, "temperature_gradient"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } void paraviewDump(Dumper & dumper) { dumper.Dump(); } diff --git a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_istropic_conductivity.cc b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_istropic_conductivity.cc index 2358b95b9..450a02e5b 100644 --- a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_istropic_conductivity.cc +++ b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_istropic_conductivity.cc @@ -1,186 +1,187 @@ /** * @file test_heat_transfer_model_cube3d_istropic_conductivity.cc * @author Rui WANG<rui.wang@epfl.ch> * @date Tue May 17 11:31:22 2011 * * @brief test of the class HeatTransferModel on the 3d cube * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "heat_transfer_model.hh" //#include "material.hh" // basic file operations #include <iostream> #include <fstream> #include <string.h> using namespace std; /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include "io_helper.h" -akantu::UInt paraview_type = TETRA1; +#include "io_helper.hh" +using namespace iohelper; +ElemType paraview_type = TETRA1; #endif //AKANTU_USE_IOHELPER akantu::UInt spatial_dimension = 3; akantu:: ElementType type = akantu::_tetrahedron_4; //just for checking #ifdef AKANTU_USE_IOHELPER void paraviewInit(Dumper & dumper); void paraviewDump(Dumper & dumper); #endif akantu::HeatTransferModel * model; akantu::UInt nb_nodes; akantu::UInt nb_element; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("cube1.msh", mesh); model = new akantu::HeatTransferModel(mesh); model->readMaterials("material.dat"); //model initialization model->initModel(); //initialize the vectors model->initVectors(); nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_element = model->getFEM().getMesh().getNbElement(type); akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); model->getTemperature().clear(); model->getTemperatureRate().clear(); //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::Vector<akantu::Real> & nodes = model->getFEM().getMesh().getNodes(); akantu::Vector<bool> & boundary = model->getBoundary(); akantu::Vector<akantu::Real> & temperature = model->getTemperature(); akantu::Real eps = 1e-15; double length = 1.; for (akantu::UInt i = 0; i < nb_nodes; ++i) { //temperature(i) = t1 - (t1 - t2) * sin(nodes(i, 0) * M_PI / length); temperature(i) = 100.; if(nodes(i,0) < eps) { boundary(i) = true; temperature(i) = 300.; } //set the second boundary condition if(std::abs(nodes(i,0) - length) < eps) { boundary(i) = true; temperature(i) = 300.; } // //to insert a heat source // if(std::abs(nodes(i,0) - length/2.) < 0.025 && std::abs(nodes(i,1) - length/2.) < 0.025 && std::abs(nodes(i,2) - length/2.) < 0.025) { // boundary(i) = true; // temperature(i) = 300.; // } } #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper); #endif model->assembleCapacityLumped(); // //for testing int max_steps = 1000; for(int i=0; i<max_steps; i++) { model->explicitPred(); model->updateResidual(); model->solveExplicitLumped(); model->explicitCorr(); #ifdef AKANTU_USE_IOHELPER if(i % 100 == 0) paraviewDump(dumper); #endif if(i % 10000 == 0) std::cout << "Step " << i << "/" << max_steps << std::endl; } cout<< "\n\n Stable Time Step is : " << time_step << "\n \n" <<endl; return 0; } #ifdef AKANTU_USE_IOHELPER void paraviewInit(Dumper & dumper) { dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates_cube3d_istropic_conductivity"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getTemperature().values, 1, "temperature"); dumper.AddNodeDataField(model->getResidual().values, 1, "residual"); dumper.AddNodeDataField(model->getTemperatureRate().values, 1, "temperature_rate"); dumper.AddNodeDataField(model->getCapacityLumped().values, 1, "capacity"); dumper.AddElemDataField(model->getTemperatureGradient(type).values, spatial_dimension, "temperature_gradient"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } void paraviewDump(Dumper & dumper) { dumper.Dump(); } #endif diff --git a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_pbc.cc b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_pbc.cc index 66d7c7f17..64660dcc9 100644 --- a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_pbc.cc +++ b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_cube3d_pbc.cc @@ -1,180 +1,181 @@ /** * @file test_heat_transfer_model_cube3d.cc * @author Rui WANG<rui.wang@epfl.ch> * @date Tue May 17 11:31:22 2011 * * @brief test of the class HeatTransferModel on the 3d cube * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "heat_transfer_model.hh" #include "pbc_synchronizer.hh" #include <iostream> #include <fstream> #include <string.h> using namespace std; /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include "io_helper.h" +#include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER #ifdef AKANTU_USE_IOHELPER -void paraviewInit(akantu::HeatTransferModel * model,Dumper & dumper); +void paraviewInit(akantu::HeatTransferModel * model, Dumper & dumper); void paraviewDump(Dumper & dumper); -akantu::UInt paraview_type = TETRA1; +ElemType paraview_type = TETRA1; #endif akantu::UInt spatial_dimension = 3; akantu:: ElementType type = akantu::_tetrahedron_4; /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("cube_tet4.msh", mesh); akantu::HeatTransferModel * model; akantu::UInt nb_nodes; akantu::UInt nb_element; model = new akantu::HeatTransferModel(mesh); /* -------------------------------------------------------------------------- */ model->readMaterials("material.dat"); model->initModel(); model->initVectors(); model->getTemperature().clear(); model->getTemperatureRate().clear(); /* -------------------------------------------------------------------------- */ model->initPBC(1,1,1); model->assembleCapacityLumped(); /* -------------------------------------------------------------------------- */ nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_element = model->getFEM().getMesh().getNbElement(type); nb_nodes = model->getFEM().getMesh().getNbNodes(); /* ------------------------------------------------------------------------ */ //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::Vector<akantu::Real> & nodes = model->getFEM().getMesh().getNodes(); akantu::Vector<bool> & boundary = model->getBoundary(); akantu::Vector<akantu::Real> & temperature = model->getTemperature(); double t1, t2, length; t1 = 300.; t2 = 100.; length = 1.; for (akantu::UInt i = 0; i < nb_nodes; ++i) { temperature(i) = 100.; akantu::Real dx = nodes(i,0) - length/4.; akantu::Real dy = nodes(i,1) - length/4.; akantu::Real dz = nodes(i,2) - length/4.; akantu::Real d = sqrt(dx*dx + dy*dy + dz*dz); if(d < 0.1){ boundary(i) = true; temperature(i) = 300.; } } /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(model,dumper); #endif /* ------------------------------------------------------------------------ */ // //for testing int max_steps = 1000; /* ------------------------------------------------------------------------ */ for(int i=0; i<max_steps; i++) { model->explicitPred(); model->updateResidual(); model->solveExplicitLumped(); model->explicitCorr(); #ifdef AKANTU_USE_IOHELPER if(i % 100 == 0) paraviewDump(dumper); #endif if(i % 10 == 0) std::cout << "Step " << i << "/" << max_steps << std::endl; } cout<< "\n\n Stable Time Step is : " << time_step << "\n \n" <<endl; return 0; } /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER void paraviewInit(akantu::HeatTransferModel * model, Dumper & dumper) { akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); akantu::UInt nb_element = model->getFEM().getMesh().getNbElement(type); dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates2"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getTemperature().values, 1, "temperature"); dumper.AddNodeDataField(model->getResidual().values, 1, "residual"); dumper.AddNodeDataField(model->getCapacityLumped().values, 1, "capacity_lumped"); // dumper.AddElemDataField(model->getTemperatureGradient(type).values, // spatial_dimension, "temperature_gradient"); // dumper.AddElemDataField(model->getbtkgt().values, // 4, "btkgt"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } #endif /* -------------------------------------------------------------------------- */ diff --git a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_square2d_pbc.cc b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_square2d_pbc.cc index 666a47011..0faf5e4cb 100644 --- a/test/test_model/test_heat_transfer_model/test_heat_transfer_model_square2d_pbc.cc +++ b/test/test_model/test_heat_transfer_model/test_heat_transfer_model_square2d_pbc.cc @@ -1,188 +1,189 @@ /** * @file test_heat_transfer_model_cube3d.cc * @author Rui WANG<rui.wang@epfl.ch> * @date Tue May 17 11:31:22 2011 * * @brief test of the class HeatTransferModel on the 3d cube * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "heat_transfer_model.hh" #include "pbc_synchronizer.hh" #include <iostream> #include <fstream> #include <string.h> using namespace std; /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include "io_helper.h" +#include "io_helper.hh" +using namespace iohelper; void paraviewInit(akantu::HeatTransferModel * model,Dumper & dumper); void paraviewDump(Dumper & dumper); -akantu::UInt paraview_type = TRIANGLE1; +ElemType paraview_type = TRIANGLE1; #endif //AKANTU_USE_IOHELPER akantu::UInt spatial_dimension = 2; akantu:: ElementType type = akantu::_triangle_3; /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { akantu::debug::setDebugLevel(akantu::dblWarning); - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("square_tri3.msh", mesh); akantu::HeatTransferModel * model; akantu::UInt nb_nodes; akantu::UInt nb_element; model = new akantu::HeatTransferModel(mesh); /* -------------------------------------------------------------------------- */ model->readMaterials("material.dat"); model->initModel(); model->initVectors(); model->getTemperature().clear(); model->getTemperatureRate().clear(); /* -------------------------------------------------------------------------- */ model->initPBC(1,1,1); model->assembleCapacityLumped(); /* -------------------------------------------------------------------------- */ nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_element = model->getFEM().getMesh().getNbElement(type); nb_nodes = model->getFEM().getMesh().getNbNodes(); /* ------------------------------------------------------------------------ */ //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::Vector<akantu::Real> & nodes = model->getFEM().getMesh().getNodes(); akantu::Vector<bool> & boundary = model->getBoundary(); akantu::Vector<akantu::Real> & temperature = model->getTemperature(); double t1, t2, length; t1 = 300.; t2 = 100.; length = 1.; 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.; } } /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(model,dumper); #endif /* ------------------------------------------------------------------------ */ // //for testing int max_steps = 100000; /* ------------------------------------------------------------------------ */ for(int i=0; i<max_steps; i++) { model->explicitPred(); model->updateResidual(); model->solveExplicitLumped(); model->explicitCorr(); #ifdef AKANTU_USE_IOHELPER if(i % 100 == 0) paraviewDump(dumper); #endif if(i % 10 == 0) std::cout << "Step " << i << "/" << max_steps << std::endl; } cout<< "\n\n Stable Time Step is : " << time_step << "\n \n" <<endl; return 0; } /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER void paraviewInit(akantu::HeatTransferModel * model, Dumper & dumper) { akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); akantu::UInt nb_element = model->getFEM().getMesh().getNbElement(type); // dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates2"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getTemperature().values, 1, "temperature"); dumper.AddNodeDataField(model->getTemperatureRate().values, 1, "temperature_rate"); dumper.AddNodeDataField(model->getResidual().values, 1, "residual"); dumper.AddNodeDataField(model->getCapacityLumped().values, 1, "capacity_lumped"); dumper.AddElemDataField(model->getTemperatureGradient(type).values, spatial_dimension, "temperature_gradient"); dumper.AddElemDataField(model->getConductivityOnQpoints(type).values, spatial_dimension*spatial_dimension, "conductivity_qpoints"); dumper.SetPrefix("paraview/"); dumper.Init(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } #endif /* -------------------------------------------------------------------------- */ diff --git a/test/test_model/test_solid_mechanics_model/patch_tests/colone_weight.cc b/test/test_model/test_solid_mechanics_model/patch_tests/colone_weight.cc index 2b08af643..0421cb010 100644 --- a/test/test_model/test_solid_mechanics_model/patch_tests/colone_weight.cc +++ b/test/test_model/test_solid_mechanics_model/patch_tests/colone_weight.cc @@ -1,226 +1,227 @@ /** * @file colone_weight.cc * @author Alodie Schneuwly <alodie.schneuwly@epfl.ch> * @date Wed Mar 23 15:42:36 2011 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "aka_vector.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { // chose if you use hexahedron elements bool use_hexa = false; std::stringstream mesh_file; std::stringstream output; std::stringstream energy_file; akantu::ElementType type; #ifdef AKANTU_USE_IOHELPER - akantu::UInt paraview_type; + ElemType paraview_type; #endif //AKANTU_USE_IOHELPER UInt vel_damping_interval; if (use_hexa) { type = akantu::_hexahedron_8; mesh_file << "colone_hexa.msh"; output << "paraview/test_weight_hexa"; energy_file << "energy_hexa.csv"; #ifdef AKANTU_USE_IOHELPER paraview_type = HEX1; #endif //AKANTU_USE_IOHELPER vel_damping_interval =4; } else { type = akantu::_tetrahedron_4; mesh_file << "colone_tetra.msh"; output << "paraview/test_weight_tetra"; energy_file << "energy_tetra.csv"; #ifdef AKANTU_USE_IOHELPER paraview_type = TETRA1; #endif //AKANTU_USE_IOHELPER vel_damping_interval = 8; } akantu::UInt spatial_dimension = 3; akantu::UInt max_steps = 2000; akantu::Real time_factor = 0.8; - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); // akantu::Real epot, ekin; akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read(mesh_file.str().c_str(), mesh); akantu::SolidMechanicsModel * model = new akantu::SolidMechanicsModel(mesh); akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); akantu::UInt nb_element = model->getFEM().getMesh().getNbElement(type); std::cout << "Nb nodes : " << nb_nodes << " - nb elements : " << nb_element << std::endl; /// model initialization model->initVectors(); /// set vectors to 0 memset(model->getForce().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getVelocity().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getAcceleration().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getDisplacement().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); model->initModel(); model->initExplicit(); model->readMaterials("material_colone.dat"); model->initMaterials(); std::cout << model->getMaterial(0) << std::endl; model->assembleMassLumped(); #ifdef AKANTU_USE_IOHELPER /// set to 0 only for the first paraview dump // memset(model->getResidual().values, 0, // spatial_dimension*nb_nodes*sizeof(akantu::Real)); // memset(model->getMaterial(0).getStrain(type).values, 0, // spatial_dimension*spatial_dimension*nb_element*sizeof(akantu::Real)); // memset(model->getMaterial(0).getStress(type).values, 0, // spatial_dimension*spatial_dimension*nb_element*sizeof(akantu::Real)); #endif //AKANTU_USE_IOHELPER /// boundary conditions const akantu::Vector<Real> & position = model->getFEM().getMesh().getNodes(); akantu::Vector<bool> & boundary = model->getBoundary(); akantu::Vector<Real> & force = model->getForce(); const akantu::Vector<Real> & mass = model->getMass(); akantu::Real z_min = position(0, 2); for (unsigned int i = 0; i < nb_nodes; ++i) { if(position(i, 2) < z_min) z_min = position(i, 2); } akantu::Real eps = 1e-13; for (akantu::UInt i = 0; i < nb_nodes; ++i) { if(fabs(position(i, 2) - z_min) <= eps) boundary(i,2) = true; else force(i,2) = -mass(i,0) * 9.81; } akantu::Real time_step = model->getStableTimeStep() * time_factor; std::cout << "Time Step = " << time_step << "s" << std::endl; model->setTimeStep(time_step); // model->setTimeStep(3.54379e-07); model->updateResidual(); #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model->getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model->getForce().values, spatial_dimension, "applied_force"); dumper.AddElemDataField(model->getMaterial(0).getStrain(type).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(type).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetPrefix(output.str().c_str()); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER akantu::Vector<Real> & velocity = model->getVelocity(); std::ofstream energy; energy.open(energy_file.str().c_str()); energy << "id,epot,ekin,tot" << std::endl; for(akantu::UInt s = 1; s <= max_steps; ++s) { model->explicitPred(); model->updateResidual(); model->updateAcceleration(); model->explicitCorr(); akantu::Real epot = model->getPotentialEnergy(); akantu::Real ekin = model->getKineticEnergy(); energy << s << "," << epot << "," << ekin << "," << epot + ekin << std::endl; if (s % vel_damping_interval == 0) { for (akantu::UInt i = 0; i < nb_nodes; ++i) { velocity(i, 0) *= 0.9; velocity(i, 1) *= 0.9; velocity(i, 2) *= 0.9; } } #ifdef AKANTU_USE_IOHELPER if(s % 1 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER if(s % 10 == 0) std::cout << "passing step " << s << "/" << max_steps << std::endl; } akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/patch_tests/explicit/patch_test_explicit.cc b/test/test_model/test_solid_mechanics_model/patch_tests/explicit/patch_test_explicit.cc index f391dc26a..5d10642c6 100644 --- a/test/test_model/test_solid_mechanics_model/patch_tests/explicit/patch_test_explicit.cc +++ b/test/test_model/test_solid_mechanics_model/patch_tests/explicit/patch_test_explicit.cc @@ -1,374 +1,374 @@ /** * @file test_check_stress.cc * @author David Kammer <david.kammer@epfl.ch> * @date Wed Feb 16 13:56:42 2011 * * @brief patch test for elastic material in solid mechanics model * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "element_class.hh" #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; Real alpha [3][4] = { { 0.01, 0.02, 0.03, 0.04 }, { 0.05, 0.06, 0.07, 0.08 }, { 0.09, 0.10, 0.11, 0.12 } }; #ifdef AKANTU_USE_IOHELPER static void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model); static void paraviewDump(Dumper & dumper); #endif /* -------------------------------------------------------------------------- */ template<ElementType type> static types::Matrix prescribed_strain() { UInt spatial_dimension = ElementClass<type>::getSpatialDimension(); types::Matrix strain(spatial_dimension, spatial_dimension); for (UInt i = 0; i < spatial_dimension; ++i) { for (UInt j = 0; j < spatial_dimension; ++j) { strain(i, j) = alpha[i][j + 1]; } } return strain; } template<ElementType type> static types::Matrix prescribed_stress() { UInt spatial_dimension = ElementClass<type>::getSpatialDimension(); types::Matrix stress(spatial_dimension, spatial_dimension); //plane strain in 2d types::Matrix strain(spatial_dimension, spatial_dimension); types::Matrix pstrain; pstrain = prescribed_strain<type>(); Real nu = 0.3; Real E = 2.1e11; Real trace = 0; /// symetric part of the strain tensor for (UInt i = 0; i < spatial_dimension; ++i) for (UInt j = 0; j < spatial_dimension; ++j) strain(i,j) = 0.5 * (pstrain(i, j) + pstrain(j, i)); for (UInt i = 0; i < spatial_dimension; ++i) trace += strain(i,i); Real Ep = E / (1 + nu); for (UInt i = 0; i < spatial_dimension; ++i) for (UInt j = 0; j < spatial_dimension; ++j) { stress(i, j) = Ep * strain(i,j); if(i == j) stress(i, j) += Ep * (nu / (1 - 2*nu)) * trace; } return stress; } /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - initialize(&argc, &argv); + initialize(argc, argv); debug::setDebugLevel(dblWarning); UInt dim = ElementClass<TYPE>::getSpatialDimension(); const ElementType element_type = TYPE; // UInt imposing_steps = 1000; // Real max_displacement = -0.01; UInt damping_steps = 400000; UInt damping_interval = 50; Real damping_ratio = 0.99; UInt additional_steps = 20000; UInt max_steps = damping_steps + additional_steps; /// load mesh Mesh my_mesh(dim); MeshIOMSH mesh_io; std::stringstream filename; filename << TYPE << ".msh"; mesh_io.read(filename.str(), my_mesh); UInt nb_nodes = my_mesh.getNbNodes(); /// declaration of model SolidMechanicsModel my_model(my_mesh); /// model initialization my_model.initVectors(); // initialize the vectors my_model.getForce().clear(); my_model.getVelocity().clear(); my_model.getAcceleration().clear(); my_model.getDisplacement().clear(); my_model.initExplicit(); my_model.initModel(); my_model.readMaterials("material_check_stress.dat"); my_model.initMaterials(); Real time_step = my_model.getStableTimeStep()/5.; my_model.setTimeStep(time_step); my_model.assembleMassLumped(); std::cout << "The number of time steps is: " << max_steps << " (" << time_step << "s)" << std::endl; // // boundary conditions // Vector<UInt> top_nodes(0, 1); // Vector<UInt> base_nodes(0, 1); const Vector<Real> & coordinates = my_mesh.getNodes(); Vector<Real> & displacement = my_model.getDisplacement(); Vector<bool> & boundary = my_model.getBoundary(); MeshUtils::buildFacets(my_mesh); MeshUtils::buildSurfaceID(my_mesh); CSR<UInt> surface_nodes; MeshUtils::buildNodesPerSurface(my_mesh, surface_nodes); //CSR<UInt>::iterator snode = surface_nodes.begin(0); for (UInt s = 0; s < surface_nodes.getNbRows(); ++s) { CSR<UInt>::iterator snode = surface_nodes.begin(s); for(; snode != surface_nodes.end(s); ++snode) { UInt n = *snode; std::cout << "Node " << n << std::endl; for (UInt i = 0; i < dim; ++i) { displacement(n, i) = alpha[i][0]; for (UInt j = 0; j < dim; ++j) { displacement(n, i) += alpha[i][j + 1] * coordinates(n, j); } boundary(n, i) = true; } // if (coordinates(n, 0) < Math::tolerance) { // boundary(n, 0) = true; // displacement(n, 0) = 0.; // } // if (coordinates(n, 1) < Math::tolerance) { // boundary(n, 1) = true; // displacement(n, 1) = 0.; // } } } Vector<Real> & velocity = my_model.getVelocity(); #ifdef AKANTU_USE_IOHELPER my_model.updateResidual(); DumperParaview dumper; paraviewInit(dumper, my_model); #endif std::ofstream energy; std::stringstream energy_filename; energy_filename << "energy_" << TYPE << ".csv"; energy.open(energy_filename.str().c_str()); energy << "id,time,ekin" << std::endl; Real ekin_mean = 0.; /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ for(UInt s = 1; s <= max_steps; ++s) { if(s % 10000 == 0) std::cout << "passing step " << s << "/" << max_steps << " (" << s*time_step << "s)" <<std::endl; // impose normal displacement // if(s <= imposing_steps) { // Real current_displacement = max_displacement / (static_cast<Real>(imposing_steps)) * s; // for(UInt n = 0; n < top_nodes.getSize(); ++n) { // UInt node = top_nodes(n); // displacement(node, 1) = current_displacement; // } // } // damp velocity in order to find equilibrium if((s < damping_steps) && (s % damping_interval == 0)) { velocity *= damping_ratio; } if(s % 1000 == 0) { ekin_mean = ekin_mean / 1000.; std::cout << "Ekin mean = " << ekin_mean << std::endl; if (ekin_mean < 1e-10) break; ekin_mean = 0.; } my_model.explicitPred(); my_model.updateResidual(); my_model.updateAcceleration(); my_model.explicitCorr(); akantu::Real ekin = my_model.getKineticEnergy();; ekin_mean += ekin; if(s % 1000 == 0) energy << s << "," << s*time_step << "," << ekin << std::endl; #ifdef AKANTU_USE_IOHELPER if(s % 10000 == 0) paraviewDump(dumper); #endif } #ifdef AKANTU_USE_IOHELPER paraviewDump(dumper); #endif energy.close(); // UInt check_element = 0; // UInt quadrature_point = 0; UInt nb_quadrature_points = my_model.getFEM().getNbQuadraturePoints(TYPE); Vector<Real> & stress_vect = const_cast<Vector<Real> &>(my_model.getMaterial(0).getStress(element_type)); Vector<Real> & strain_vect = const_cast<Vector<Real> &>(my_model.getMaterial(0).getStrain(element_type)); Vector<Real>::iterator<types::Matrix> stress_it = stress_vect.begin(dim, dim); Vector<Real>::iterator<types::Matrix> strain_it = strain_vect.begin(dim, dim); types::Matrix presc_stress; presc_stress = prescribed_stress<TYPE>(); types::Matrix presc_strain; presc_strain = prescribed_strain<TYPE>(); UInt nb_element = my_mesh.getNbElement(TYPE); for (UInt el = 0; el < nb_element; ++el) { for (UInt q = 0; q < nb_quadrature_points; ++q) { types::Matrix & stress = *stress_it; types::Matrix & strain = *strain_it; for (UInt i = 0; i < dim; ++i) { for (UInt j = 0; j < dim; ++j) { if(!(std::abs(strain(i, j) - presc_strain(i, j)) < 1e-9)) { std::cerr << "strain[" << i << "," << j << "] = " << strain(i, j) << " but should be = " << presc_strain(i, j) << " (-" << std::abs(strain(i, j) - presc_strain(i, j)) << ") [el : " << el<< " - q : " << q << "]" << std::endl; std::cerr << strain << presc_strain << std::endl; return EXIT_FAILURE; } if(!(std::abs(stress(i, j) - presc_stress(i, j)) < 1e2)) { std::cerr << "stress[" << i << "," << j << "] = " << stress(i, j) << " but should be = " << presc_stress(i, j) << " (-" << std::abs(stress(i, j) - presc_stress(i, j)) << ") [el : " << el<< " - q : " << q << "]" << std::endl; std::cerr << stress << presc_stress << std::endl; return EXIT_FAILURE; } } } ++stress_it; ++strain_it; } } for (UInt n = 0; n < nb_nodes; ++n) { for (UInt i = 0; i < dim; ++i) { Real disp = alpha[i][0]; for (UInt j = 0; j < dim; ++j) { disp += alpha[i][j + 1] * coordinates(n, j); } if(!(std::abs(displacement(n,i) - disp) < 1e-7)) { std::cerr << "displacement(" << n << ", " << i <<")=" << displacement(n,i) << " should be equal to " << disp << "(" << displacement(n,i) - disp << ")" << std::endl; return EXIT_FAILURE; } } } // std::cout << "Strain : " << strain; // std::cout << "Stress : " << stress; finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ /* Dumper vars */ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -template <ElementType type> -static UInt paraviewType(); - -template <> UInt paraviewType<_segment_2>() { return LINE1; } -template <> UInt paraviewType<_segment_3>() { return LINE2; } -template <> UInt paraviewType<_triangle_3>() { return TRIANGLE1; } -template <> UInt paraviewType<_triangle_6>() { return TRIANGLE2; } -template <> UInt paraviewType<_quadrangle_4>() { return QUAD1; } -template <> UInt paraviewType<_quadrangle_8>() { return QUAD2; } -template <> UInt paraviewType<_tetrahedron_4>() { return TETRA1; } -template <> UInt paraviewType<_tetrahedron_10>() { return TETRA2; } -template <> UInt paraviewType<_hexahedron_8>() { return HEX1; } +template <ElementType type> static ElemType paraviewType(); + +template <> ElemType paraviewType<_segment_2>() { return LINE1; } +template <> ElemType paraviewType<_segment_3>() { return LINE2; } +template <> ElemType paraviewType<_triangle_3>() { return TRIANGLE1; } +template <> ElemType paraviewType<_triangle_6>() { return TRIANGLE2; } +template <> ElemType paraviewType<_quadrangle_4>() { return QUAD1; } +template <> ElemType paraviewType<_quadrangle_8>() { return QUAD2; } +template <> ElemType paraviewType<_tetrahedron_4>() { return TETRA1; } +template <> ElemType paraviewType<_tetrahedron_10>() { return TETRA2; } +template <> ElemType paraviewType<_hexahedron_8>() { return HEX1; } void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model) { UInt spatial_dimension = ElementClass<TYPE>::getSpatialDimension(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); UInt nb_element = model.getFEM().getMesh().getNbElement(TYPE); std::stringstream filename; filename << "out_" << TYPE; dumper.SetMode(TEXT); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, filename.str().c_str()); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(TYPE).values, paraviewType<TYPE>(), nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model.getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model.getMass().values, 1, "mass"); dumper.AddNodeDataField(model.getForce().values, spatial_dimension, "applied_force"); dumper.AddElemDataField(model.getMaterial(0).getStrain(TYPE).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model.getMaterial(0).getStrain(TYPE).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } #endif diff --git a/test/test_model/test_solid_mechanics_model/patch_tests/implicit/patch_test_implicit.cc b/test/test_model/test_solid_mechanics_model/patch_tests/implicit/patch_test_implicit.cc index c8d442c74..54b0f0e6e 100644 --- a/test/test_model/test_solid_mechanics_model/patch_tests/implicit/patch_test_implicit.cc +++ b/test/test_model/test_solid_mechanics_model/patch_tests/implicit/patch_test_implicit.cc @@ -1,308 +1,308 @@ /** * @file test_check_stress.cc * @author David Kammer <david.kammer@epfl.ch> * @date Wed Feb 16 13:56:42 2011 * * @brief patch test for elastic material in solid mechanics model * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "element_class.hh" #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; Real alpha [3][4] = { { 0.01, 0.02, 0.03, 0.04 }, { 0.05, 0.06, 0.07, 0.08 }, { 0.09, 0.10, 0.11, 0.12 } }; /* -------------------------------------------------------------------------- */ template<ElementType type> types::Matrix prescribed_strain() { UInt spatial_dimension = ElementClass<type>::getSpatialDimension(); types::Matrix strain(spatial_dimension, spatial_dimension); for (UInt i = 0; i < spatial_dimension; ++i) { for (UInt j = 0; j < spatial_dimension; ++j) { strain(i, j) = alpha[i][j + 1]; } } return strain; } template<ElementType type> types::Matrix prescribed_stress() { UInt spatial_dimension = ElementClass<type>::getSpatialDimension(); types::Matrix stress(spatial_dimension, spatial_dimension); //plane strain in 2d types::Matrix strain(spatial_dimension, spatial_dimension); types::Matrix pstrain; pstrain = prescribed_strain<type>(); Real nu = 0.3; Real E = 2.1e11; Real trace = 0; /// symetric part of the strain tensor for (UInt i = 0; i < spatial_dimension; ++i) for (UInt j = 0; j < spatial_dimension; ++j) strain(i,j) = 0.5 * (pstrain(i, j) + pstrain(j, i)); for (UInt i = 0; i < spatial_dimension; ++i) trace += strain(i,i); Real Ep = E / (1 + nu); for (UInt i = 0; i < spatial_dimension; ++i) for (UInt j = 0; j < spatial_dimension; ++j) { stress(i, j) = Ep * strain(i,j); if(i == j) stress(i, j) += Ep * (nu / (1 - 2*nu)) * trace; } return stress; } /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model); void paraviewDump(Dumper & dumper); #endif /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - initialize(&argc, &argv); + initialize(argc, argv); UInt dim = ElementClass<TYPE>::getSpatialDimension(); const ElementType element_type = TYPE; /// load mesh Mesh my_mesh(dim); MeshIOMSH mesh_io; std::stringstream filename; filename << TYPE << ".msh"; mesh_io.read(filename.str(), my_mesh); UInt nb_nodes = my_mesh.getNbNodes(); /// declaration of model SolidMechanicsModel my_model(my_mesh); /// model initialization my_model.initVectors(); // initialize the vectors my_model.getForce().clear(); my_model.getVelocity().clear(); my_model.getAcceleration().clear(); my_model.getDisplacement().clear(); my_model.initModel(); my_model.readMaterials("material_check_stress.dat"); my_model.initMaterials(); my_model.initImplicit(); const Vector<Real> & coordinates = my_mesh.getNodes(); Vector<Real> & displacement = my_model.getDisplacement(); Vector<bool> & boundary = my_model.getBoundary(); MeshUtils::buildFacets(my_mesh); MeshUtils::buildSurfaceID(my_mesh); CSR<UInt> surface_nodes; MeshUtils::buildNodesPerSurface(my_mesh, surface_nodes); for (UInt s = 0; s < surface_nodes.getNbRows(); ++s) { CSR<UInt>::iterator snode = surface_nodes.begin(s); for(; snode != surface_nodes.end(s); ++snode) { UInt n = *snode; std::cout << "Node " << n << std::endl; for (UInt i = 0; i < dim; ++i) { displacement(n, i) = alpha[i][0]; for (UInt j = 0; j < dim; ++j) { displacement(n, i) += alpha[i][j + 1] * coordinates(n, j); } boundary(n, i) = true; } } } /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ akantu::UInt count = 0; my_model.updateResidual(); #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper, my_model); #endif while(!my_model.testConvergenceResidual(2e-4) && (count < 100)) { std::cout << "Iter : " << ++count << std::endl; my_model.assembleStiffnessMatrix(); my_model.solveStatic(); my_model.updateResidual(); } #ifdef AKANTU_USE_IOHELPER paraviewDump(dumper); #endif if(count > 1) { std::cerr << "The code did not converge in 1 step !" << std::endl; return EXIT_FAILURE; } /* ------------------------------------------------------------------------ */ /* Checks */ /* ------------------------------------------------------------------------ */ UInt nb_quadrature_points = my_model.getFEM().getNbQuadraturePoints(element_type); Vector<Real> & stress_vect = const_cast<Vector<Real> &>(my_model.getMaterial(0).getStress(element_type)); Vector<Real> & strain_vect = const_cast<Vector<Real> &>(my_model.getMaterial(0).getStrain(element_type)); Vector<Real>::iterator<types::Matrix> stress_it = stress_vect.begin(dim, dim); Vector<Real>::iterator<types::Matrix> strain_it = strain_vect.begin(dim, dim); types::Matrix presc_stress; presc_stress = prescribed_stress<TYPE>(); types::Matrix presc_strain; presc_strain = prescribed_strain<TYPE>(); UInt nb_element = my_mesh.getNbElement(TYPE); for (UInt el = 0; el < nb_element; ++el) { for (UInt q = 0; q < nb_quadrature_points; ++q) { types::Matrix & stress = *stress_it; types::Matrix & strain = *strain_it; for (UInt i = 0; i < dim; ++i) { for (UInt j = 0; j < dim; ++j) { if(!(std::abs(strain(i, j) - presc_strain(i, j)) < 1e-15)) { std::cerr << "strain[" << i << "," << j << "] = " << strain(i, j) << " but should be = " << presc_strain(i, j) << " (-" << std::abs(strain(i, j) - presc_strain(i, j)) << ") [el : " << el<< " - q : " << q << "]" << std::endl; std::cerr << "computed : " << strain << "reference : " << presc_strain << std::endl; return EXIT_FAILURE; } if(!(std::abs(stress(i, j) - presc_stress(i, j)) < 1e-3)) { std::cerr << "stress[" << i << "," << j << "] = " << stress(i, j) << " but should be = " << presc_stress(i, j) << " (-" << std::abs(stress(i, j) - presc_stress(i, j)) << ") [el : " << el<< " - q : " << q << "]" << std::endl; std::cerr << "computed : " << stress << "reference : " << presc_stress << std::endl; return EXIT_FAILURE; } } } ++stress_it; ++strain_it; } } for (UInt n = 0; n < nb_nodes; ++n) { for (UInt i = 0; i < dim; ++i) { Real disp = alpha[i][0]; for (UInt j = 0; j < dim; ++j) { disp += alpha[i][j + 1] * coordinates(n, j); } if(!(std::abs(displacement(n,i) - disp) < 1e-15)) { std::cerr << "displacement(" << n << ", " << i <<")=" << displacement(n,i) << " should be equal to " << disp << std::endl; return EXIT_FAILURE; } } } // std::cout << "Strain : " << strain; // std::cout << "Stress : " << stress; // finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ /* Dumper vars */ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -template <ElementType type> -UInt paraviewType(); - -template <> UInt paraviewType<_segment_2>() { return LINE1; }; -template <> UInt paraviewType<_segment_3>() { return LINE2; }; -template <> UInt paraviewType<_triangle_3>() { return TRIANGLE1; }; -template <> UInt paraviewType<_triangle_6>() { return TRIANGLE2; }; -template <> UInt paraviewType<_quadrangle_4>() { return QUAD1; }; -template <> UInt paraviewType<_quadrangle_8>() { return QUAD2; }; -template <> UInt paraviewType<_tetrahedron_4>() { return TETRA1; }; -template <> UInt paraviewType<_tetrahedron_10>() { return TETRA2; }; -template <> UInt paraviewType<_hexahedron_8>() { return HEX1; }; +template <ElementType type> ElemType paraviewType(); + +template <> ElemType paraviewType<_segment_2>() { return LINE1; }; +template <> ElemType paraviewType<_segment_3>() { return LINE2; }; +template <> ElemType paraviewType<_triangle_3>() { return TRIANGLE1; }; +template <> ElemType paraviewType<_triangle_6>() { return TRIANGLE2; }; +template <> ElemType paraviewType<_quadrangle_4>() { return QUAD1; }; +template <> ElemType paraviewType<_quadrangle_8>() { return QUAD2; }; +template <> ElemType paraviewType<_tetrahedron_4>() { return TETRA1; }; +template <> ElemType paraviewType<_tetrahedron_10>() { return TETRA2; }; +template <> ElemType paraviewType<_hexahedron_8>() { return HEX1; }; void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model) { UInt spatial_dimension = ElementClass<TYPE>::getSpatialDimension(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); UInt nb_element = model.getFEM().getMesh().getNbElement(TYPE); std::stringstream filename; filename << "out_" << TYPE; dumper.SetMode(TEXT); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, filename.str().c_str()); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(TYPE).values, paraviewType<TYPE>(), nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model.getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model.getMass().values, 1, "mass"); dumper.AddNodeDataField(model.getForce().values, spatial_dimension, "applied_force"); dumper.AddElemDataField(model.getMaterial(0).getStrain(TYPE).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model.getMaterial(0).getStrain(TYPE).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } #endif diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_2d/test_contact_2d_expli/test_contact_2d_expli.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_2d/test_contact_2d_expli/test_contact_2d_expli.cc index d1c84508f..c30a30a25 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_2d/test_contact_2d_expli/test_contact_2d_expli.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_2d/test_contact_2d_expli/test_contact_2d_expli.cc @@ -1,278 +1,279 @@ /** * @file test_contact_2d_expli.cc * @author Leonardo Snozzi <leonardo.snozzi@epfl.ch> * @date Fri Nov 26 07:43:47 2010 * * @brief test explicit DCR contact algorithm for 2d * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_2d_explicit.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include "io_helper.h" +#include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER #define NORMAL_PRESSURE -1.e6 using namespace akantu; //static void reduceGap(const SolidMechanicsModel & model, const Real threshold, const Real gap); static void setBoundaryConditions(SolidMechanicsModel & model); void my_force(Real * coord, Real * T, Real * normal, UInt surface_id); static void reduceVelocities(const SolidMechanicsModel & model, const Real ratio); static void initParaview(SolidMechanicsModel & model); Real y_min, y_max; #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; #endif int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); UInt spatial_dimension = 2; UInt max_steps = 30000; Real time_factor = 0.2; Mesh mesh(spatial_dimension); MeshIOMSH mesh_io; mesh_io.read("squares.msh", mesh); SolidMechanicsModel * model = new SolidMechanicsModel(mesh); /// get two squares closer // reduceGap(*model, 0.05, 1.e-6); UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); UInt nb_elements = model->getFEM().getMesh().getNbElement(_triangle_3); /// model initialization model->initModel(); model->initVectors(); model->readMaterials("materials.dat"); model->initMaterials(); model->initExplicit(); std::cout << model->getMaterial(0) << std::endl; model->assembleMassLumped(); /// set vectors to zero memset(model->getForce().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getVelocity().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getAcceleration().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getDisplacement().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getResidual().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getMaterial(0).getStrain(_triangle_3).values, 0, spatial_dimension*spatial_dimension*nb_elements*sizeof(Real)); memset(model->getMaterial(0).getStress(_triangle_3).values, 0, spatial_dimension*spatial_dimension*nb_elements*sizeof(Real)); /// Paraview Helper #ifdef AKANTU_USE_IOHELPER initParaview(*model); #endif //AKANTU_USE_IOHELPER Real time_step = model->getStableTimeStep() * time_factor; std::cout << "Time Step = " << time_step << "s" << std::endl; model->setTimeStep(time_step); /// set boundary conditions setBoundaryConditions(*model); /// define and initialize contact Contact * contact = Contact::newContact(*model, _ct_2d_expli, _cst_2d_expli, _cnst_2d_grid); Contact2dExplicit * my_contact = dynamic_cast<Contact2dExplicit *>(contact); my_contact->initContact(true); my_contact->setFrictionCoefficient(0.); my_contact->initNeighborStructure(); my_contact->initSearch(); for (UInt s = 0; s < max_steps; ++s) { model->explicitPred(); model->updateCurrentPosition(); my_contact->solveContact(); model->updateResidual(); model->updateAcceleration(); model->explicitCorr(); #ifdef AKANTU_USE_IOHELPER if(s % 200 == 0) dumper.Dump(); #endif if(s%100 == 0 && s>499) reduceVelocities(*model, 0.95); if(s % 500 == 0) std::cout << "passing step " << s << "/" << max_steps << std::endl; } delete my_contact; delete model; finalize(); return EXIT_SUCCESS; } // /* -------------------------------------------------------------------------- */ // static void reduceGap(const SolidMechanicsModel & model, const Real threshold, const Real gap) { // UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); // Real * coord = model.getFEM().getMesh().getNodes().values; // Real y_top = HUGE_VAL, y_bot = -HUGE_VAL; // for (UInt n = 0; n < nb_nodes; ++n) { // if (coord[2*n+1] > threshold) { // if(coord[2*n+1] < y_top) // y_top = coord[2*n+1]; // } // else { // if (coord[2*n+1] > y_bot) // y_bot = coord[2*n+1]; // } // } // Real delta = y_top - y_bot - gap; // /// move all nodes belonging to the top cube // for (UInt n = 0; n < nb_nodes; ++n) { // if (coord[2*n+1] > threshold) // coord[2*n+1] -= delta; // } // } /* -------------------------------------------------------------------------- */ static void setBoundaryConditions(SolidMechanicsModel & model) { UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); Real * coord = model.getFEM().getMesh().getNodes().values; for (UInt n = 0; n < nb_nodes; ++n) { if (coord[2*n+1] > y_max) y_max = coord[2*n+1]; if (coord[2*n+1] < y_min) y_min = coord[2*n+1]; } FEM & b_fem = model.getFEMBoundary(); b_fem.initShapeFunctions(); b_fem.computeNormalsOnControlPoints(); bool * id = model.getBoundary().values; memset(id, 0, 2*nb_nodes*sizeof(bool)); std::cout << "Nodes "; for (UInt i = 0; i < nb_nodes; ++i) { if (coord[2*i+1] < y_min + 1.e-5) { id[2*i+1] = true; std::cout << " " << i << " "; } } std::cout << "are blocked" << std::endl; model.computeForcesFromFunction(my_force, _bft_stress); } /* -------------------------------------------------------------------------- */ void my_force(Real * coord, Real * T, __attribute__ ((unused)) Real * normal, __attribute__ ((unused)) UInt surface_id) { memset(T, 0, 4*sizeof(double)); if(*(coord+1) > y_max-1.e-5) T[3] = NORMAL_PRESSURE; } /* -------------------------------------------------------------------------- */ /// artificial damping of velocities in order to reach a global static equilibrium static void reduceVelocities(const SolidMechanicsModel & model, const Real ratio) { UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); Real * velocities = model.getVelocity().values; if(ratio>1.) { fprintf(stderr,"**error** in Reduce_Velocities ratio bigger than 1!\n"); exit(-1); } for(UInt i =0; i<nb_nodes; i++) { velocities[2*i] *= ratio; velocities[2*i+1] *= ratio; } } /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER static void initParaview(SolidMechanicsModel & model) { UInt spatial_dimension = model.getSpatialDimension(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); UInt nb_elements = model.getFEM().getMesh().getNbElement(_triangle_3); dumper.SetMode(TEXT); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(_triangle_3).values, TRIANGLE1, nb_elements, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model.getResidual().values, spatial_dimension, "force"); dumper.AddElemDataField(model.getMaterial(0).getStrain(_triangle_3).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model.getMaterial(0).getStress(_triangle_3).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } #endif diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_2d/test_contact_2d_expli_fric/test_contact_2d_expli_fric.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_2d/test_contact_2d_expli_fric/test_contact_2d_expli_fric.cc index 825cbbfbe..baf09a595 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_2d/test_contact_2d_expli_fric/test_contact_2d_expli_fric.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_2d/test_contact_2d_expli_fric/test_contact_2d_expli_fric.cc @@ -1,295 +1,295 @@ /** * @file test_contact_2d_expli.cc * @author Leonardo Snozzi <leonardo.snozzi@epfl.ch> * @date Fri Nov 26 07:43:47 2010 * * @brief test explicit DCR contact algorithm for 2d * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" -#include "io_helper.h" +#include "io_helper.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include "io_helper.h" +#include "io_helper.hh" #endif //AKANTU_USE_IOHELPER #define NORMAL_PRESSURE -1.e6 #define IMP_VEL 1. using namespace akantu; class Boundary { public: Boundary(Mesh & mesh, SolidMechanicsModel & model); virtual ~Boundary(); reduceGap(const Real threshold, const Real gap); setBoundaryConditions(); public: public: private: /// SolidMechanicsModel & model; /// Mesh & mesh; Real top_bounds[]; Real }; static void static void setBoundaryConditions(SolidMechanicsModel & model); void my_force(double * coord, double *T); static void reduceVelocities(const SolidMechanicsModel & model, const Real ratio); static void initParaview(SolidMechanicsModel & model); Real y_min, y_max; DumperParaview dumper; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); UInt spatial_dimension = 2; UInt max_steps = 30000; Real time_factor = 0.2; Mesh mesh(spatial_dimension); MeshIOMSH mesh_io; mesh_io.read("squares.msh", mesh); SolidMechanicsModel * model = new SolidMechanicsModel(mesh); /// get two squares closer // reduceGap(*model, 0.05, 1.e-6); UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); UInt nb_elements = model->getFEM().getMesh().getNbElement(_triangle_3); /// model initialization model->initVectors(); model->readMaterials("materials.dat"); model->initMaterials(); model->initModel(); std::cout << model->getMaterial(0) << std::endl; model->assembleMassLumped(); /// set vectors to zero memset(model->getForce().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getVelocity().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getAcceleration().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getDisplacement().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getResidual().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getMaterial(0).getStrain(_triangle_3).values, 0, spatial_dimension*spatial_dimension*nb_elements*sizeof(Real)); memset(model->getMaterial(0).getStress(_triangle_3).values, 0, spatial_dimension*spatial_dimension*nb_elements*sizeof(Real)); /// Paraview Helper #ifdef AKANTU_USE_IOHELPER initParaview(*model); #endif //AKANTU_USE_IOHELPER Real time_step = model->getStableTimeStep() * time_factor; std::cout << "Time Step = " << time_step << "s" << std::endl; model->setTimeStep(time_step); /// set boundary conditions Boundary * my_boudary; setBoundaryConditions(*model); /// define and initialize contact Contact * my_contact = Contact::newContact(*model, _ct_2d_expli, _cst_2d_expli, _cnst_2d_grid); my_contact->initContact(true); my_contact->setFrictionCoefficient(0.); my_contact->initNeighborStructure(); my_contact->initSearch(); for (UInt s = 0; s < max_steps; ++s) { model->explicitPred(); model->updateCurrentPosition(); my_contact->solveContact(); model->updateResidual(); model->updateAcceleration(); model->explicitCorr(); if(s % 200 == 0) dumper.Dump(); if(s%100 == 0 && s>499) reduceVelocities(*model, 0.95); if(s % 500 == 0) std::cout << "passing step " << s << "/" << max_steps << std::endl; } delete my_boudary; delete my_contact; delete model; finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ static void reduceGap(const SolidMechanicsModel & model, const Real threshold, const Real gap) { UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); Real * coord = model.getFEM().getMesh().getNodes().values; Real y_top = HUGE_VAL, y_bot = -HUGE_VAL; for (UInt n = 0; n < nb_nodes; ++n) { if (coord[2*n+1] > threshold) { if(coord[2*n+1] < y_top) y_top = coord[2*n+1]; } else { if (coord[2*n+1] > y_bot) y_bot = coord[2*n+1]; } } Real delta = y_top - y_bot - gap; /// move all nodes belonging to the top cube for (UInt n = 0; n < nb_nodes; ++n) { if (coord[2*n+1] > threshold) coord[2*n+1] -= delta; } } /* -------------------------------------------------------------------------- */ static void setBoundaryConditions(SolidMechanicsModel & model) { UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); Real * coord = model.getFEM().getMesh().getNodes().values; for (UInt n = 0; n < nb_nodes; ++n) { if (coord[2*n+1] > y_max) y_max = coord[2*n+1]; if (coord[2*n+1] < y_min) y_min = coord[2*n+1]; } FEM & b_fem = model.getFEMBoundary(); b_fem.initShapeFunctions(); b_fem.computeNormalsOnQuadPoints(); bool * id = model.getBoundary().values; memset(id, 0, 2*nb_nodes*sizeof(bool)); std::cout << "Nodes "; for (UInt i = 0; i < nb_nodes; ++i) { if (coord[2*i+1] < y_min + 1.e-5) { id[2*i+1] = true; std::cout << " " << i << " "; } } std::cout << "are blocked" << std::endl; model.computeForcesFromFunction(my_force, _bft_stress); } /* -------------------------------------------------------------------------- */ void my_force(double * coord, double *T) { memset(T, 0, 4*sizeof(double)); if(*(coord+1) > y_max-1.e-5) T[3] = NORMAL_PRESSURE; } /* -------------------------------------------------------------------------- */ /// artificial damping of velocities in order to reach a global static equilibrium static void reduceVelocities(const SolidMechanicsModel & model, const Real ratio) { UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); Real * velocities = model.getVelocity().values; if(ratio>1.) { fprintf(stderr,"**error** in Reduce_Velocities ratio bigger than 1!\n"); exit(-1); } for(UInt i =0; i<nb_nodes; i++) { velocities[2*i] *= ratio; velocities[2*i+1] *= ratio; } } /* -------------------------------------------------------------------------- */ static void initParaview(SolidMechanicsModel & model) { UInt spatial_dimension = model.getSpatialDimension(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); UInt nb_elements = model.getFEM().getMesh().getNbElement(_triangle_3); dumper.SetMode(TEXT); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(_triangle_3).values, TRIANGLE1, nb_elements, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model.getResidual().values, spatial_dimension, "force"); dumper.AddElemDataField(model.getMaterial(0).getStrain(_triangle_3).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model.getMaterial(0).getStress(_triangle_3).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/io_helper_tools.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/io_helper_tools.cc index d7d55e1ea..4b673f843 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/io_helper_tools.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/io_helper_tools.cc @@ -1,294 +1,294 @@ /** * @file io_helper_tools.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Sep 30 11:13:01 2011 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "io_helper_tools.hh" #include "aka_common.hh" #include "mesh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "static_communicator.hh" // #include "dof_synchronizer.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; /* ------------------------------------------------------------------------ */ template <ElementType type> -static UInt getIOHelperType() { AKANTU_DEBUG_TO_IMPLEMENT(); return -1; }; - -template <> UInt getIOHelperType<_segment_2>() { return LINE1; } -template <> UInt getIOHelperType<_segment_3>() { return LINE2; } -template <> UInt getIOHelperType<_triangle_3>() { return TRIANGLE1; } -template <> UInt getIOHelperType<_triangle_6>() { return TRIANGLE2; } -template <> UInt getIOHelperType<_quadrangle_4>() { return QUAD1; } -template <> UInt getIOHelperType<_quadrangle_8>() { return QUAD2; } -template <> UInt getIOHelperType<_tetrahedron_4>() { return TETRA1; } -template <> UInt getIOHelperType<_tetrahedron_10>() { return TETRA2; } -template <> UInt getIOHelperType<_hexahedron_8>() { return HEX1; } - -static UInt getIOHelperType(ElementType type) { - UInt ioh_type = -1; +static ElemType getIOHelperType() { AKANTU_DEBUG_TO_IMPLEMENT(); return MAX_ELEM_TYPE; }; + +template <> ElemType getIOHelperType<_segment_2>() { return LINE1; } +template <> ElemType getIOHelperType<_segment_3>() { return LINE2; } +template <> ElemType getIOHelperType<_triangle_3>() { return TRIANGLE1; } +template <> ElemType getIOHelperType<_triangle_6>() { return TRIANGLE2; } +template <> ElemType getIOHelperType<_quadrangle_4>() { return QUAD1; } +template <> ElemType getIOHelperType<_quadrangle_8>() { return QUAD2; } +template <> ElemType getIOHelperType<_tetrahedron_4>() { return TETRA1; } +template <> ElemType getIOHelperType<_tetrahedron_10>() { return TETRA2; } +template <> ElemType getIOHelperType<_hexahedron_8>() { return HEX1; } + +static ElemType getIOHelperType(ElementType type) { + ElemType ioh_type; #define GET_IOHELPER_TYPE(type) \ ioh_type = getIOHelperType<type>(); AKANTU_BOOST_ELEMENT_SWITCH(GET_IOHELPER_TYPE); #undef GET_IOHELPER_TYPE return ioh_type; } /* ------------------------------------------------------------------------ */ void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model, const ElementType & type, const std::string & filename) { const Mesh & mesh = model.getFEM().getMesh(); UInt spatial_dimension = mesh.getSpatialDimension(type); UInt nb_nodes = mesh.getNbNodes(); UInt nb_element = mesh.getNbElement(type); std::stringstream filename_sstr; filename_sstr << filename << "_" << type; UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); UInt nproc = StaticCommunicator::getStaticCommunicator()->getNbProc(); dumper.SetMode(TEXT); dumper.SetParallelContext(whoami, nproc); dumper.SetPoints(mesh.getNodes().values, spatial_dimension, nb_nodes, filename_sstr.str().c_str()); dumper.SetConnectivity((int *)mesh.getConnectivity(type).values, getIOHelperType(type), nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model.getAcceleration().values, spatial_dimension, "acceleration"); dumper.AddNodeDataField(model.getMass().values, spatial_dimension, "mass"); dumper.AddNodeDataField(model.getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model.getForce().values, spatial_dimension, "applied_force"); dumper.AddElemDataField(model.getMaterial(0).getStrain(type).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model.getMaterial(0).getStress(type).values, spatial_dimension*spatial_dimension, "stress"); if(dynamic_cast<const MaterialDamage *>(&model.getMaterial(0))) { const MaterialDamage & mat = dynamic_cast<const MaterialDamage &>(model.getMaterial(0)); Real * dam = mat.getDamage(type).storage(); dumper.AddElemDataField(dam, 1, "damage"); } dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* ------------------------------------------------------------------------ */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ // Vector<Real> checkpoint_displacements(0, spatial_dimension); // Vector<Real> checkpoint_velocity(0, spatial_dimension); // Vector<Real> checkpoint_acceleration(0, spatial_dimension); // Vector<Real> checkpoint_force(0, spatial_dimension); // /* ------------------------------------------------------------------------ */ // void checkpointInit(Dumper & dumper, // const SolidMechanicsModel & model, // const ElementType & type, // const std::string & filename) { // UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); // UInt nproc = StaticCommunicator::getStaticCommunicator()->getNbProc(); // Vector<Real> & displacements = model.getDisplacement(); // Vector<Real> & velocity = model.getVelocity(); // Vector<Real> & acceleration = model.getAcceleration(); // Vector<Real> & force = model.getForce(); // DOFSynchronizer & dof_synchronizer = const_cast<DOFSynchronizer &>(model.getDOFSynchronizer()); // dof_synchronizer.initScatterGatherCommunicationScheme(); // if(whoami == 0){ // const Mesh & mesh = model.getFEM().getMesh(); // UInt nb_nodes = mesh.getNbGlobalNodes(); // checkpoint_displacements.resize(nb_nodes); // checkpoint_velocity .resize(nb_nodes); // checkpoint_acceleration .resize(nb_nodes); // checkpoint_force .resize(nb_nodes); // dof_synchronizer.gather(displacements, 0, &checkpoint_displacements); // dof_synchronizer.gather(velocity , 0, &checkpoint_velocity ); // dof_synchronizer.gather(acceleration , 0, &checkpoint_acceleration ); // dof_synchronizer.gather(force , 0, &checkpoint_force ); // UInt nb_element = mesh.getNbElement(type); // UInt spatial_dimension = mesh.getSpatialDimension(type); // std::stringstream filename_sstr; filename_sstr << filename << "_" << type; // dumper.SetMode(COMPRESSED); // dumper.SetParallelContext(whoami, nproc); // dumper.SetPoints(mesh.getNodes().values, // spatial_dimension, nb_nodes, filename_sstr.str().c_str()); // dumper.SetConnectivity((int *)mesh.getConnectivity(type).values, // getIOHelperType(type), nb_element, C_MODE); // dumper.AddNodeDataField(checkpoint_displacements.storage(), spatial_dimension, "displacements"); // dumper.AddNodeDataField(checkpoint_velocity .storage(), spatial_dimension, "velocity"); // dumper.AddNodeDataField(checkpoint_acceleration .storage(), spatial_dimension, "acceleration"); // dumper.AddNodeDataField(checkpoint_force .storage(), spatial_dimension, "applied_force"); // dumper.SetPrefix("restart/"); // dumper.Init(); // dumper.Dump(); // } else { // dof_synchronizer.gather(displacements, 0); // dof_synchronizer.gather(velocity , 0); // dof_synchronizer.gather(acceleration , 0); // dof_synchronizer.gather(force , 0); // } // } // /* ------------------------------------------------------------------------ */ // void checkpoint(Dumper & dumper, // const SolidMechanicsModel & model) { // UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); // DOFSynchronizer & dof_synchronizer = const_cast<DOFSynchronizer &>(model.getDOFSynchronizer()); // Vector<Real> & displacements = model.getDisplacement(); // Vector<Real> & velocity = model.getVelocity(); // Vector<Real> & acceleration = model.getAcceleration(); // Vector<Real> & force = model.getForce(); // if(whoami == 0){ // dof_synchronizer.gather(displacements, 0, &checkpoint_displacements); // dof_synchronizer.gather(velocity , 0, &checkpoint_velocity ); // dof_synchronizer.gather(acceleration , 0, &checkpoint_acceleration ); // dof_synchronizer.gather(force , 0, &checkpoint_force ); // dumper.Dump(); // } else { // dof_synchronizer.gather(displacements, 0); // dof_synchronizer.gather(velocity , 0); // dof_synchronizer.gather(acceleration , 0); // dof_synchronizer.gather(force , 0); // } // } // /* ------------------------------------------------------------------------ */ // /* ------------------------------------------------------------------------ */ // void restart(const SolidMechanicsModel & model, // const ElementType & type, // const std::string & filename) { // UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); // UInt nproc = StaticCommunicator::getStaticCommunicator()->getNbProc(); // DOFSynchronizer & dof_synchronizer = const_cast<DOFSynchronizer &>(model.getDOFSynchronizer()); // dof_synchronizer.initScatterGatherCommunicationScheme(); // Vector<Real> & displacements = model.getDisplacement(); // Vector<Real> & velocity = model.getVelocity(); // Vector<Real> & acceleration = model.getAcceleration(); // Vector<Real> & force = model.getForce(); // if(whoami == 0){ // const Mesh & mesh = model.getFEM().getMesh(); // UInt nb_nodes = mesh.getNbGlobalNodes(); // UInt spatial_dimension = mesh.getSpatialDimension(type); // std::stringstream filename_sstr; filename_sstr << filename << "_" << type; // ReaderRestart reader; // reader.SetMode(COMPRESSED); // reader.SetParallelContext(whoami, nproc); // reader.SetPoints(filename_sstr.str().c_str()); // reader.SetConnectivity(getIOHelperType(type)); // reader.AddNodeDataField("displacements"); // reader.AddNodeDataField("velocity"); // reader.AddNodeDataField("acceleration"); // reader.AddNodeDataField("applied_force"); // reader.SetPrefix("restart/"); // reader.Init(); // reader.Read(); // Vector<Real> restart_tmp_vect(nb_nodes, spatial_dimension); // displacements.clear(); // velocity.clear(); // acceleration.clear(); // force.clear(); // Real * tmp = reader.GetNodeDataField("displacements"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(displacements, 0, &restart_tmp_vect); // tmp = reader.GetNodeDataField("velocity"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(velocity , 0, &restart_tmp_vect); // tmp = reader.GetNodeDataField("acceleration"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(acceleration , 0, &restart_tmp_vect); // tmp = reader.GetNodeDataField("applied_force"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(force , 0, &restart_tmp_vect); // } else { // displacements.clear(); // velocity.clear(); // acceleration.clear(); // force.clear(); // dof_synchronizer.scatter(displacements, 0); // dof_synchronizer.scatter(velocity , 0); // dof_synchronizer.scatter(acceleration , 0); // dof_synchronizer.scatter(force , 0); // } // } /* ------------------------------------------------------------------------ */ diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/io_helper_tools.hh b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/io_helper_tools.hh index f9098b366..13d22c486 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/io_helper_tools.hh +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/io_helper_tools.hh @@ -1,53 +1,54 @@ /** * @file io_helper_tools.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Sep 30 11:15:18 2011 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "solid_mechanics_model.hh" -#include "io_helper.h" +#include "io_helper.hh" +using namespace iohelper; extern const akantu::UInt spatial_dimension; /* ------------------------------------------------------------------------ */ void paraviewInit(Dumper & dumper, const akantu::SolidMechanicsModel & model, const akantu::ElementType & type, const std::string & filename); void paraviewDump(Dumper & dumper); // void checkpointInit(Dumper & dumper, // const akantu::SolidMechanicsModel & model, // const akantu::ElementType & type, // const std::string & filename); // void checkpoint(Dumper & dumper, // const akantu::SolidMechanicsModel & model); // void restart(const akantu::SolidMechanicsModel & model, // const akantu::ElementType & type, // const std::string & filename); diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/patch_tests/test_single_spring_friction.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/patch_tests/test_single_spring_friction.cc index 30dc5879c..981b7ea20 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/patch_tests/test_single_spring_friction.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/patch_tests/test_single_spring_friction.cc @@ -1,511 +1,512 @@ /** * @file test_single_spring_friction.cc * @author David Kammer <david.kammer@epfl.ch> * @date Wed May 25 10:46:40 2011 * * @brief test with analytical solution for friction of a single spring * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <stdio.h> #include <stdlib.h> #ifdef AKANTU_USE_IOHELPER -#include <io_helper.h> +#include <io_helper.hh> +using namespace iohelper; #endif //AKANTU_USE_IOHELPER #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "friction_coefficient.hh" #include "unique_constant_fric_coef.hh" #include "velocity_weakening_coulomb.hh" #include "contact_neighbor_structure.hh" #include "regular_grid_neighbor_structure.hh" #include "contact_search.hh" #include "contact_search_explicit.hh" using namespace akantu; /* -------------------------------------------------------------------------- */ Surface impactor = 0; Surface master = 1; UInt the_node = 0; const ElementType element_type = _triangle_3; #ifdef AKANTU_USE_IOHELPER -const UInt paraview_type = TRIANGLE1; +const ElemType paraview_type = TRIANGLE1; #endif //AKANTU_USE_IOHELPER const char* mesh_name = "single_triangle.msh"; const char* folder_name = "single_spring_friction"; std::string result_name; const bool viscous_mat = false; const bool vel_weak_coulomb = false; Real mu_s = 0.3; Real mu_d = 0.2; const UInt paraview_dump_int = 1e3; const UInt file_dump_int = 1e2; const UInt max_steps = 1e6; const UInt stick_stop = 3; Real n_k = 0.15; Real normal_force; Real start_displacement = 0.2; Mesh * mesh; SolidMechanicsModel * model; UInt spatial_dimension = 2; Real time_step_security = 3.; Real time_step; UInt nb_nodes; UInt nb_elements; UInt stick_counter = 0; bool patch_test = false; const Real tolerance = std::numeric_limits<Real>::epsilon() * 10.; // variables of model Real * coordinates; Real * displacement; Real * current_position; Real * velocity; Real * residual; Real * acceleration; bool * boundary; Real * force; Real * mass; std::map < std::string, VectorBase* > restart_map; #ifdef AKANTU_USE_IOHELPER void paraviewInit(Dumper & dumper); #endif //AKANTU_USE_IOHELPER void loadRestartInformation(ContactRigid * contact); void printPredictor(UInt step, std::ofstream & out_stream); void printCorrector(UInt step, ContactRigid * contact, std::ofstream & out_stream); void getStickInfo(ContactRigid * contact); bool testFloat(Real a, Real b, Real adm_error); /* -------------------------------------------------------------------------- */ Int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); debug::setDebugLevel(dblWarning); // 1: name // 2: initial displacement // 3: friction coefficient // 4: ratio N/K with N normal force & K stiffness if (argc == 5) { result_name = argv[1]; start_displacement = atof(argv[2]); mu_s = atof(argv[3]); n_k = atof(argv[4]); } else { result_name = "patch_test_output"; patch_test = true; // return EXIT_FAILURE; } /// load mesh mesh = new Mesh(spatial_dimension); MeshIOMSH mesh_io; mesh_io.read(mesh_name, *mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(*mesh,1,0); MeshUtils::buildSurfaceID(*mesh); /// declaration of model model = new SolidMechanicsModel(*mesh); nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_elements = model->getFEM().getMesh().getNbElement(element_type); std::cout << "Nb nodes : " << nb_nodes << " - nb elements : " << nb_elements << std::endl; /// model initialization model->initVectors(); // initialize the vectors model->getForce().clear(); model->getVelocity().clear(); model->getAcceleration().clear(); model->getDisplacement().clear(); model->initExplicit(); model->initModel(); /// read and initialize material if(viscous_mat) model->readMaterials("material_elastic_caughey.dat"); else model->readMaterials("material.dat"); model->initMaterials(); Real stable_time_step = model->getStableTimeStep(); time_step = stable_time_step/time_step_security; model->setTimeStep(time_step); std::cout << "The time step is " << time_step << std::endl; // accessors to model elements coordinates = mesh->getNodes().values; displacement = model->getDisplacement().values; velocity = model->getVelocity().values; acceleration = model->getAcceleration().values; boundary = model->getBoundary().values; residual = model->getResidual().values; model->updateCurrentPosition(); current_position = model->getCurrentPosition().values; force = model->getForce().values; mass = model->getMass().values; model->assembleMassLumped(); UInt nb_surfaces = mesh->getNbSurfaces(); nb_surfaces += 1; /// contact declaration Contact * contact_structure = Contact::newContact(*model, _ct_rigid, _cst_expli, _cnst_regular_grid); ContactRigid * contact = dynamic_cast<ContactRigid *>(contact_structure); //contact->initContact(false); contact->addMasterSurface(master); contact->addImpactorSurfaceToMasterSurface(impactor, master); /// define the friction law FrictionCoefficient *fric_coef; if(vel_weak_coulomb) fric_coef = new VelocityWeakeningCoulomb(*contact, master, mu_s, mu_d); else fric_coef = new UniqueConstantFricCoef(*contact, master, mu_s); // load restart file loadRestartInformation(contact); // set boundary condition displacement[the_node*spatial_dimension] = start_displacement; model->updateCurrentPosition(); model->updateResidual(); Real stiffness = std::abs(residual[the_node * spatial_dimension] / start_displacement); normal_force = n_k * stiffness; force[the_node*spatial_dimension+1] = -normal_force; if (start_displacement > tolerance) { std::cout << "Start displacement = " << start_displacement << " ; Residual = " << residual[the_node*spatial_dimension] << " -> Stiffness K = " << stiffness << std::endl; std::cout << "Mass = " << mass[the_node] << std::endl; } else std::cout << "No start displacement!! " << std::endl; /// initialize the paraview output #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; #endif //AKANTU_USE_IOHELPER std::ofstream out_info; if (!patch_test) { model->updateResidual(); #ifdef AKANTU_USE_IOHELPER paraviewInit(dumper); #endif //AKANTU_USE_IOHELPER /// output files std::stringstream name_info; name_info << "output_files/" << folder_name << "/global_info.dat"; out_info.open(name_info.str().c_str()); out_info << "%id time fnorm fres ffric ftot mu disp vel stick ekin epot etot" << std::endl; } UInt step = 0; Real previous_vel = 0.; UInt count_cycle = 0; /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ while(stick_counter <= stick_stop && step <= max_steps) { // increase step step += 1; if(step % 1000 == 0) { std::cout << "passing step " << step << "/" << max_steps << "\r"; std::cout.flush(); } model->explicitPred(); model->updateResidual(); if (step % file_dump_int == 0 && !patch_test) printPredictor(step, out_info); contact->frictionPredictor(); model->updateAcceleration(); model->explicitCorr(); contact->frictionCorrector(); // see if node sticks getStickInfo(contact); // count numbers of cycles if (Math::are_float_equal(velocity[the_node * spatial_dimension], 0.) && !Math::are_float_equal(previous_vel, 0.)) count_cycle++; previous_vel = velocity[the_node * spatial_dimension]; if(step % file_dump_int == 0 && !patch_test) printCorrector(step, contact, out_info); #ifdef AKANTU_USE_IOHELPER if(step % paraview_dump_int == 0 && !patch_test) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } std::cout << "passing step " << step << "/" << max_steps << std::endl; Real final_displacement = displacement[the_node * spatial_dimension]; // check patch test if(patch_test) { Real correct_final_disp = 0.0200181; Real admissible_error = 1e-07; UInt correct_nb_cycle = 2; //if (!(Math::are_float_equal(final_displacement, correct_final_disp)) | !(count_cycle == correct_nb_cycle)) { if (!(testFloat(final_displacement, correct_final_disp, admissible_error)) | !(count_cycle == correct_nb_cycle)) { std::cout << "Final displacement is " << final_displacement << ", which should be " << correct_final_disp << std::endl; std::cout << "Final number of cycles is " << count_cycle << ", which should be " << correct_nb_cycle << std::endl; return EXIT_FAILURE; } else { std::cout << "Patch test successful!" << std::endl; return EXIT_SUCCESS; } } else { /// output files std::stringstream result_name_path; result_name_path << "output_files/" << folder_name << "/" << result_name << ".dat"; std::ofstream out_result; out_result.open(result_name_path.str().c_str(), std::ios::app); if (!out_result.good()) { std::cout << "Could not open result file " << std::endl; return EXIT_FAILURE; } out_result << start_displacement << " " << final_displacement << " " << count_cycle << std::endl; out_result.close(); } out_info.close(); delete fric_coef; delete contact; delete model; delete mesh; finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER void paraviewInit(Dumper & dumper) { std::stringstream name; name << "paraview/" << folder_name << "/"; dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(element_type).values, paraview_type, nb_elements, C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model->getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model->getMass().values, 1, "mass"); dumper.AddNodeDataField(model->getForce().values, spatial_dimension, "applied_force"); dumper.AddElemDataField(model->getMaterial(0).getStrain(element_type).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(element_type).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix(name.str().c_str()); dumper.Init(); dumper.Dump(); } #endif //AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ void loadRestartInformation(ContactRigid * contact) { // boundary conditions Vector<bool> * boundary_r = new Vector<bool>(nb_nodes, spatial_dimension, false); // sticked nodes (*boundary_r)(1,0) = true; (*boundary_r)(1,1) = true; (*boundary_r)(2,0) = true; (*boundary_r)(2,1) = true; // the impactor node (*boundary_r)(0,1) = true; memcpy(boundary, boundary_r->values, spatial_dimension*nb_nodes*sizeof(bool)); // set the active impactor node Vector<bool> * ai_nodes = new Vector<bool>(nb_nodes, 1, false); (*ai_nodes)(the_node) = true; restart_map["active_impactor_nodes"] = ai_nodes; // not defined master type, because won't use solve contact Vector<ElementType> * et_nodes = new Vector<ElementType>(nb_nodes, 1, _not_defined); restart_map["master_element_type"] = et_nodes; // master normal x=0; y=1 Vector<Real> * mn_nodes = new Vector<Real>(0, spatial_dimension); Real normal[spatial_dimension]; normal[0] = 0.; normal[1] = 1.; mn_nodes->push_back(normal); restart_map["master_normals"] = mn_nodes; // node is sticking Vector<bool> * is_nodes = new Vector<bool>(nb_nodes, 2, false); (*is_nodes)(0,0) = true; (*is_nodes)(0,1) = true; restart_map["node_is_sticking"] = is_nodes; // no friction force Vector<Real> * ff_nodes = new Vector<Real>(0, spatial_dimension); Real force[spatial_dimension]; force[0] = 0.; force[1] = 0.; ff_nodes->push_back(force); restart_map["friction_forces"] = ff_nodes; // the original stick position (for regularized friction) Vector<Real> * sp_nodes = new Vector<Real>(0, spatial_dimension); Real position[spatial_dimension]; position[0] = 0.; position[1] = 0.; sp_nodes->push_back(position); restart_map["stick_positions"] = sp_nodes; // no residual forces Vector<Real> * rf_nodes = new Vector<Real>(0, spatial_dimension); Real r_force[spatial_dimension]; r_force[0] = 0.; r_force[1] = 0.; rf_nodes->push_back(r_force); restart_map["residual_forces"] = rf_nodes; // no previous velocities Vector<Real> * pv_nodes = new Vector<Real>(0, spatial_dimension); Real vel[spatial_dimension]; vel[0] = 0.; vel[1] = 0.; pv_nodes->push_back(vel); restart_map["previous_velocities"] = pv_nodes; contact->setRestartInformation(restart_map, master); delete boundary_r; delete ai_nodes; delete et_nodes; delete mn_nodes; delete is_nodes; delete ff_nodes; delete sp_nodes; delete rf_nodes; delete pv_nodes; } /* -------------------------------------------------------------------------- */ void printPredictor(UInt step, std::ofstream & out_stream) { out_stream << step << " " << step*time_step << " " << residual[the_node*spatial_dimension + 1] << " " << residual[the_node * spatial_dimension]; } /* -------------------------------------------------------------------------- */ void printCorrector(UInt step, ContactRigid * contact, std::ofstream & out_stream) { Real epot = model->getPotentialEnergy(); Real ekin = model->getKineticEnergy(); // find index of master surface in impactors_information ContactRigid::SurfaceToImpactInfoMap::const_iterator it_imp; it_imp = contact->getImpactorsInformation().find(master); // find the total contact force and contact area ContactRigid::ImpactorInformationPerMaster * imp_info = it_imp->second; Real * friction_forces_val = imp_info->friction_forces->values; bool * sticking_nodes_val = imp_info->node_is_sticking->values; out_stream << " " << friction_forces_val[0] << " " << residual[the_node * spatial_dimension] << " " << friction_forces_val[0] / residual[the_node * spatial_dimension + 1] << " " << displacement[the_node * spatial_dimension] << " " << velocity[the_node * spatial_dimension] << " " << sticking_nodes_val[0] << " " << ekin << " " << epot << " " << ekin+epot << std::endl; if (sticking_nodes_val[0]) stick_counter++; else stick_counter = 0; } /* -------------------------------------------------------------------------- */ void getStickInfo(ContactRigid * contact) { // find index of master surface in impactors_information ContactRigid::SurfaceToImpactInfoMap::const_iterator it_imp; it_imp = contact->getImpactorsInformation().find(master); // find the total contact force and contact area ContactRigid::ImpactorInformationPerMaster * imp_info = it_imp->second; bool * sticking_nodes_val = imp_info->node_is_sticking->values; if (sticking_nodes_val[the_node*2]) stick_counter++; else stick_counter = 0; } /* -------------------------------------------------------------------------- */ bool testFloat(Real a, Real b, Real adm_error) { if (fabs(a-b) < adm_error) return true; else return false; } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/patch_tests/test_single_spring_friction_w_visco.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/patch_tests/test_single_spring_friction_w_visco.cc index 137a4f3d8..5f4475b77 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/patch_tests/test_single_spring_friction_w_visco.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/patch_tests/test_single_spring_friction_w_visco.cc @@ -1,518 +1,519 @@ /** * @file test_single_spring_friction_w_visco.cc * @author David Kammer <david.kammer@epfl.ch> * @date Mon May 30 15:09:23 2011 * * @brief test for friction of elastic material with viscosity * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <stdio.h> #include <stdlib.h> #ifdef AKANTU_USE_IOHELPER -#include <io_helper.h> +#include <io_helper.hh> +using namespace iohelper; #endif //AKANTU_USE_IOHELPER #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "friction_coefficient.hh" #include "unique_constant_fric_coef.hh" #include "velocity_weakening_coulomb.hh" #include "contact_neighbor_structure.hh" #include "regular_grid_neighbor_structure.hh" #include "contact_search.hh" #include "contact_search_explicit.hh" using namespace akantu; /* -------------------------------------------------------------------------- */ Surface impactor = 0; Surface master = 1; UInt the_node = 0; const ElementType element_type = _triangle_3; #ifdef AKANTU_USE_IOHELPER -const UInt paraview_type = TRIANGLE1; +const ElemType paraview_type = TRIANGLE1; #endif //AKANTU_USE_IOHELPER const char* mesh_name = "single_triangle.msh"; const char* folder_name = "single_spring_friction_w_visco"; std::string result_name; bool viscous_mat = true; Real viscous_factor = 1e-7; const bool vel_weak_coulomb = false; Real mu_s = 0.3; Real mu_d = 0.2; UInt paraview_dump_int = 1;//e3; UInt file_dump_int = 1;//e2; UInt max_steps = 1e6; UInt stick_stop = 3; Real n_k = 0.15; Real m_k = 3.5e-08; Real normal_force; Real start_displacement = 0.2; Mesh * mesh; SolidMechanicsModel * model; UInt spatial_dimension = 2; Real time_step_security = 10.;//3.; Real time_step; UInt nb_nodes; UInt nb_elements; UInt stick_counter = 0; bool patch_test = false; const Real tolerance = std::numeric_limits<Real>::epsilon() * 10.; // variables of model Real * coordinates; Real * displacement; Real * current_position; Real * velocity; Real * residual; Real * acceleration; bool * boundary; Real * force; Real * mass; std::map < std::string, VectorBase* > restart_map; #ifdef AKANTU_USE_IOHELPER void paraviewInit(Dumper & dumper); #endif //AKANTU_USE_IOHELPER void loadRestartInformation(ContactRigid * contact); void printPredictor(UInt step, std::ofstream & out_stream); void printCorrector(UInt step, ContactRigid * contact, std::ofstream & out_stream); void getStickInfo(ContactRigid * contact); bool testFloat(Real a, Real b, Real adm_error); /* -------------------------------------------------------------------------- */ Int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); debug::setDebugLevel(dblWarning); // 1: name // 2: initial displacement // 3: friction coefficient // 4: ratio N/K with N normal force & K stiffness // 5 ratio M/K with M mass & K stiffness // 6: viscous factor alpha if (argc == 7) { result_name = argv[1]; start_displacement = atof(argv[2]); mu_s = atof(argv[3]); n_k = atof(argv[4]); m_k = atof(argv[5]); viscous_factor = atof(argv[6]); } else { result_name = "patch_test_output"; patch_test = true; // return EXIT_FAILURE; } /// load mesh mesh = new Mesh(spatial_dimension); MeshIOMSH mesh_io; mesh_io.read(mesh_name, *mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(*mesh,1,0); MeshUtils::buildSurfaceID(*mesh); /// declaration of model model = new SolidMechanicsModel(*mesh); nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_elements = model->getFEM().getMesh().getNbElement(element_type); std::cout << "Nb nodes : " << nb_nodes << " - nb elements : " << nb_elements << std::endl; /// model initialization model->initVectors(); // initialize the vectors model->getForce().clear(); model->getVelocity().clear(); model->getAcceleration().clear(); model->getDisplacement().clear(); model->initExplicit(); model->initModel(); /// read and initialize material model->readMaterials("material_elastic_caughey.dat"); MaterialElasticCaughey & my_mat = dynamic_cast<MaterialElasticCaughey & > (model->getMaterial(0)); my_mat.setAlpha(viscous_factor); model->initMaterials(); Real stable_time_step = model->getStableTimeStep(); time_step = stable_time_step/time_step_security; model->setTimeStep(time_step); std::cout << "The time step is " << time_step << std::endl; // accessors to model elements coordinates = mesh->getNodes().values; displacement = model->getDisplacement().values; velocity = model->getVelocity().values; acceleration = model->getAcceleration().values; boundary = model->getBoundary().values; residual = model->getResidual().values; model->updateCurrentPosition(); current_position = model->getCurrentPosition().values; force = model->getForce().values; mass = model->getMass().values; model->assembleMassLumped(); UInt nb_surfaces = mesh->getNbSurfaces(); nb_surfaces += 1; /// contact declaration Contact * contact_structure = Contact::newContact(*model, _ct_rigid, _cst_expli, _cnst_regular_grid); ContactRigid * contact = dynamic_cast<ContactRigid *>(contact_structure); //contact->initContact(false); contact->addMasterSurface(master); contact->addImpactorSurfaceToMasterSurface(impactor, master); /// define the friction law FrictionCoefficient *fric_coef; if(vel_weak_coulomb) fric_coef = new VelocityWeakeningCoulomb(*contact, master, mu_s, mu_d); else fric_coef = new UniqueConstantFricCoef(*contact, master, mu_s); // load restart file loadRestartInformation(contact); // set boundary condition displacement[the_node*spatial_dimension] = start_displacement; model->updateCurrentPosition(); model->updateResidual(); Real stiffness = std::abs(residual[the_node * spatial_dimension] / start_displacement); normal_force = n_k * stiffness; Real node_mass = m_k * stiffness; force[the_node*spatial_dimension+1] = -normal_force; mass[the_node] = node_mass; if (start_displacement > tolerance) { std::cout << "Start displacement = " << start_displacement << " ; Residual = " << residual[the_node*spatial_dimension] << " -> Stiffness K = " << stiffness << std::endl; std::cout << "Mass = " << node_mass << std::endl; } else std::cout << "No start displacement!! " << std::endl; /// initialize the paraview output #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; #endif //AKANTU_USE_IOHELPER std::ofstream out_info; if (!patch_test) { model->updateResidual(); #ifdef AKANTU_USE_IOHELPER paraviewInit(dumper); #endif //AKANTU_USE_IOHELPER /// output files std::stringstream name_info; name_info << "output_files/" << folder_name << "/global_info.dat"; out_info.open(name_info.str().c_str()); out_info << "%id time fnorm fres ffric ftot mu disp vel stick ekin epot etot" << std::endl; } UInt step = 0; Real previous_vel = 0.; UInt count_cycle = 0; /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ while(stick_counter <= stick_stop && step <= max_steps) { // increase step step += 1; if(step % 1000 == 0) { std::cout << "passing step " << step << "/" << max_steps << "\r"; std::cout.flush(); } model->explicitPred(); model->updateResidual(); if (step % file_dump_int == 0 && !patch_test) printPredictor(step, out_info); contact->frictionPredictor(); model->updateAcceleration(); model->explicitCorr(); contact->frictionCorrector(); // see if node sticks getStickInfo(contact); // count numbers of cycles if (Math::are_float_equal(velocity[the_node * spatial_dimension], 0.) && !Math::are_float_equal(previous_vel, 0.)) count_cycle++; previous_vel = velocity[the_node * spatial_dimension]; if(step % file_dump_int == 0 && !patch_test) printCorrector(step, contact, out_info); #ifdef AKANTU_USE_IOHELPER if(step % paraview_dump_int == 0 && !patch_test) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } std::cout << "passing step " << step << "/" << max_steps << std::endl; Real final_displacement = displacement[the_node * spatial_dimension]; // check patch test if(patch_test) { Real correct_final_disp = 0.0198331; Real admissible_error = 1e-07; UInt correct_nb_cycle = 2; //if (!(Math::are_float_equal(final_displacement, correct_final_disp)) | !(count_cycle == correct_nb_cycle)) { if (!(testFloat(final_displacement, correct_final_disp, admissible_error)) | !(count_cycle == correct_nb_cycle)) { std::cout << "Final displacement is " << final_displacement << ", which should be " << correct_final_disp << std::endl; std::cout << "Final number of cycles is " << count_cycle << ", which should be " << correct_nb_cycle << std::endl; return EXIT_FAILURE; } else { std::cout << "Patch test successful!" << std::endl; return EXIT_SUCCESS; } } /// output files if(!patch_test) { std::stringstream result_name_path; result_name_path << "output_files/" << folder_name << "/" << result_name << ".dat"; std::ofstream out_result; out_result.open(result_name_path.str().c_str(), std::ios::app); if (!out_result.good()) { std::cout << "Could not open result file " << std::endl; return EXIT_FAILURE; } out_result << start_displacement << " " << final_displacement << " " << count_cycle << std::endl; out_result.close(); } out_info.close(); delete fric_coef; delete contact; delete model; delete mesh; finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER void paraviewInit(Dumper & dumper) { std::stringstream name; name << "paraview/" << folder_name << "/"; dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(element_type).values, paraview_type, nb_elements, C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model->getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model->getMass().values, 1, "mass"); dumper.AddNodeDataField(model->getForce().values, spatial_dimension, "applied_force"); dumper.AddElemDataField(model->getMaterial(0).getStrain(element_type).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(element_type).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix(name.str().c_str()); dumper.Init(); dumper.Dump(); } #endif //AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ void loadRestartInformation(ContactRigid * contact) { // boundary conditions Vector<bool> * boundary_r = new Vector<bool>(nb_nodes, spatial_dimension, false); // sticked nodes (*boundary_r)(1,0) = true; (*boundary_r)(1,1) = true; (*boundary_r)(2,0) = true; (*boundary_r)(2,1) = true; // the impactor node (*boundary_r)(0,1) = true; memcpy(boundary, boundary_r->values, spatial_dimension*nb_nodes*sizeof(bool)); // set the active impactor node Vector<bool> * ai_nodes = new Vector<bool>(nb_nodes, 1, false); (*ai_nodes)(the_node) = true; restart_map["active_impactor_nodes"] = ai_nodes; // not defined master type, because won't use solve contact Vector<ElementType> * et_nodes = new Vector<ElementType>(nb_nodes, 1, _not_defined); restart_map["master_element_type"] = et_nodes; // master normal x=0; y=1 Vector<Real> * mn_nodes = new Vector<Real>(0, spatial_dimension); Real normal[spatial_dimension]; normal[0] = 0.; normal[1] = 1.; mn_nodes->push_back(normal); restart_map["master_normals"] = mn_nodes; // node is sticking Vector<bool> * is_nodes = new Vector<bool>(nb_nodes, 2, false); (*is_nodes)(0,0) = true; (*is_nodes)(0,1) = true; restart_map["node_is_sticking"] = is_nodes; // no friction force Vector<Real> * ff_nodes = new Vector<Real>(0, spatial_dimension); Real force[spatial_dimension]; force[0] = 0.; force[1] = 0.; ff_nodes->push_back(force); restart_map["friction_forces"] = ff_nodes; // the original stick position (for regularized friction) Vector<Real> * sp_nodes = new Vector<Real>(0, spatial_dimension); Real position[spatial_dimension]; position[0] = 0.; position[1] = 0.; sp_nodes->push_back(position); restart_map["stick_positions"] = sp_nodes; // no residual forces Vector<Real> * rf_nodes = new Vector<Real>(0, spatial_dimension); Real r_force[spatial_dimension]; r_force[0] = 0.; r_force[1] = 0.; rf_nodes->push_back(r_force); restart_map["residual_forces"] = rf_nodes; // no previous velocities Vector<Real> * pv_nodes = new Vector<Real>(0, spatial_dimension); Real vel[spatial_dimension]; vel[0] = 0.; vel[1] = 0.; pv_nodes->push_back(vel); restart_map["previous_velocities"] = pv_nodes; contact->setRestartInformation(restart_map, master); delete boundary_r; delete ai_nodes; delete et_nodes; delete mn_nodes; delete is_nodes; delete ff_nodes; delete sp_nodes; delete rf_nodes; delete pv_nodes; } /* -------------------------------------------------------------------------- */ void printPredictor(UInt step, std::ofstream & out_stream) { out_stream << step << " " << step*time_step << " " << residual[the_node*spatial_dimension + 1] << " " << residual[the_node * spatial_dimension]; } /* -------------------------------------------------------------------------- */ void printCorrector(UInt step, ContactRigid * contact, std::ofstream & out_stream) { Real epot = model->getPotentialEnergy(); Real ekin = model->getKineticEnergy(); // find index of master surface in impactors_information ContactRigid::SurfaceToImpactInfoMap::const_iterator it_imp; it_imp = contact->getImpactorsInformation().find(master); // find the total contact force and contact area ContactRigid::ImpactorInformationPerMaster * imp_info = it_imp->second; Real * friction_forces_val = imp_info->friction_forces->values; bool * sticking_nodes_val = imp_info->node_is_sticking->values; out_stream << " " << friction_forces_val[0] << " " << residual[the_node * spatial_dimension] << " " << friction_forces_val[0] / residual[the_node * spatial_dimension + 1] << " " << displacement[the_node * spatial_dimension] << " " << velocity[the_node * spatial_dimension] << " " << sticking_nodes_val[0] << " " << ekin << " " << epot << " " << ekin+epot << std::endl; if (sticking_nodes_val[0]) stick_counter++; else stick_counter = 0; } /* -------------------------------------------------------------------------- */ void getStickInfo(ContactRigid * contact) { // find index of master surface in impactors_information ContactRigid::SurfaceToImpactInfoMap::const_iterator it_imp; it_imp = contact->getImpactorsInformation().find(master); // find the total contact force and contact area ContactRigid::ImpactorInformationPerMaster * imp_info = it_imp->second; bool * sticking_nodes_val = imp_info->node_is_sticking->values; if (sticking_nodes_val[the_node*2]) stick_counter++; else stick_counter = 0; } /* -------------------------------------------------------------------------- */ bool testFloat(Real a, Real b, Real adm_error) { if (fabs(a-b) < adm_error) return true; else return false; } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_contact_rigid_no_friction.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_contact_rigid_no_friction.cc index 5e9ef1e6d..613bc4b1c 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_contact_rigid_no_friction.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_contact_rigid_no_friction.cc @@ -1,245 +1,245 @@ /** * @file test_contact_rigid_no_friction.cc * @author David Kammer <david.kammer@epfl.ch> * @date Thu Oct 6 13:51:36 2011 * * @brief test rigid contact for all types * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "contact_neighbor_structure.hh" #include "regular_grid_neighbor_structure.hh" #include "contact_search.hh" #include "contact_search_explicit.hh" #ifdef AKANTU_USE_IOHELPER # include "io_helper_tools.hh" #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); const ElementType element_type = TYPE; UInt dim = Mesh::getSpatialDimension(element_type); /// load mesh Mesh my_mesh(dim); MeshIOMSH mesh_io; std::stringstream meshname_sstr; meshname_sstr << element_type << ".msh"; mesh_io.read(meshname_sstr.str().c_str(), my_mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(my_mesh,1,0); MeshUtils::buildSurfaceID(my_mesh); UInt max_steps = 3; unsigned int nb_nodes = my_mesh.getNbNodes(); /// declaration of model SolidMechanicsModel my_model(my_mesh); /// model initialization my_model.initVectors(); // initialize the vectors my_model.getForce().clear(); my_model.getVelocity().clear(); my_model.getAcceleration().clear(); my_model.getDisplacement().clear(); Real * displacement = my_model.getDisplacement().values; Real * residual = my_model.getResidual().values; my_model.initExplicit(); my_model.initModel(); my_model.readMaterials("material.dat"); my_model.initMaterials(); /// dump facet and surface information to paraview #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper, my_model, element_type, "para"); #endif //AKANTU_USE_IOHELPER Real time_step = my_model.getStableTimeStep(); my_model.setTimeStep(time_step/10.); my_model.assembleMassLumped(); /// contact declaration Contact * contact = Contact::newContact(my_model, _ct_rigid, _cst_expli, _cnst_regular_grid); ContactRigid * my_contact = dynamic_cast<ContactRigid *>(contact); my_contact->initContact(false); Surface master = 0; Surface impactor = 1; my_contact->addMasterSurface(master); my_contact->addImpactorSurfaceToMasterSurface(impactor, master); my_model.updateCurrentPosition(); // neighbor structure uses current position for init my_contact->initNeighborStructure(master); /// define output file for testing std::stringstream filename_sstr; filename_sstr << "test_contact_rigid_no_friction_" << element_type << ".out"; std::ofstream test_output; test_output.open(filename_sstr.str().c_str()); /* const NodesNeighborList & my_neighbor_list = dynamic_cast<const NodesNeighborList &>(my_contact->getContactSearch().getContactNeighborStructure(master).getNeighborList()); UInt nb_nodes_neigh = my_neighbor_list.impactor_nodes.getSize(); Vector<UInt> impact_nodes = my_neighbor_list.impactor_nodes; UInt * impact_nodes_val = impact_nodes.values; UInt * master_nodes_offset_val = my_neighbor_list.master_nodes_offset.values; UInt * master_nodes_val = my_neighbor_list.master_nodes.values; /// print impactor nodes test_output << "we have " << nb_nodes_neigh << " impactor nodes:"; for (UInt i = 0; i < nb_nodes_neigh; ++i) { test_output << " " << impact_nodes_val[i]; } test_output << std::endl; for (UInt i = 0; i < nb_nodes_neigh; ++i) { test_output << " Impactor node: " << impact_nodes_val[i] << " has master nodes:"; for(UInt mn = master_nodes_offset_val[i]; mn < master_nodes_offset_val[i+1]; ++mn) { test_output << " " << master_nodes_val[mn]; } test_output << std::endl; } */ my_contact->initSearch(); // does nothing so far /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ for(UInt s = 1; s <= max_steps; ++s) { test_output << std::endl << "passing step " << s << "/" << max_steps << std::endl; /// apply a displacement to the slave body if(s == 2) { Real * coord = my_mesh.getNodes().values; for(UInt n = 0; n < nb_nodes; ++n) { if(coord[n*dim + 0] > 0.5) { displacement[n*dim+0] = -0.02; } } } /// integration my_model.explicitPred(); my_model.initializeUpdateResidualData(); /* /// compute the penetration list test_output << "Before solveContact" << std::endl; PenetrationList * my_penetration_list = new PenetrationList("penetration_list_1"); const_cast<ContactSearch &>(my_contact->getContactSearch()).findPenetration(master, *my_penetration_list); UInt nb_nodes_pen = my_penetration_list->penetrating_nodes.getSize(); Vector<UInt> pen_nodes = my_penetration_list->penetrating_nodes; UInt * pen_nodes_val = pen_nodes.values; test_output << "we have " << nb_nodes_pen << " penetrating nodes:" << std::endl; for (UInt i = 0; i < nb_nodes_pen; ++i) { test_output << "node " << pen_nodes_val[i] << " with disp:"; for (UInt j=0; j<dim; ++j) test_output << " " << std::setprecision(10) << displacement[pen_nodes_val[i]*dim+j]; test_output << std::endl; } test_output << std::endl; delete my_penetration_list; */ /// solve contact my_contact->solveContact(); /* /// compute the penetration list test_output << "After solveContact" << std::endl; PenetrationList * my_penetration_list_2 = new PenetrationList("penetration_list_2"); const_cast<ContactSearch &>(my_contact->getContactSearch()).findPenetration(master, *my_penetration_list_2); UInt nb_nodes_pen_2 = my_penetration_list_2->penetrating_nodes.getSize(); Vector<UInt> pen_nodes_2 = my_penetration_list_2->penetrating_nodes; UInt * pen_nodes_2_val = pen_nodes_2.values; test_output << "we have " << nb_nodes_pen_2 << " penetrating nodes:"; for (UInt i = 0; i < nb_nodes_pen_2; ++i) test_output << " " << pen_nodes_2_val[i]; test_output << std::endl; delete my_penetration_list_2; */ /// compute the residual my_model.updateResidual(false); ContactRigid::SurfaceToImpactInfoMap::const_iterator it_imp; it_imp = my_contact->getImpactorsInformation().find(master); ContactRigid::ImpactorInformationPerMaster * imp_info = it_imp->second; UInt * active_imp_nodes_val = imp_info->active_impactor_nodes->values; test_output << "we have " << imp_info->active_impactor_nodes->getSize() << " active impactor nodes:" << std::endl; for (UInt i = 0; i < imp_info->active_impactor_nodes->getSize(); ++i) { UInt node = active_imp_nodes_val[i]; test_output << "node " << node << " with disp:"; for (UInt j=0; j<dim; ++j) test_output << " " << std::setprecision(10) << displacement[node*dim+j]; test_output << " and force:"; for (UInt j=0; j<dim; ++j) test_output << " " << std::setprecision(10) << residual[node*dim+j]; test_output << std::endl; } // further integration my_contact->avoidAdhesion(); my_model.updateAcceleration(); my_model.explicitCorr(); #ifdef AKANTU_USE_IOHELPER paraviewDump(dumper); #endif //AKANTU_USE_IOHELPER } delete my_contact; finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_contact_rigid_restart.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_contact_rigid_restart.cc index cfae4cf34..ee799fe1d 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_contact_rigid_restart.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_contact_rigid_restart.cc @@ -1,590 +1,591 @@ /** * @file test_contact_rigid_restart_triangle_3.cc * @author David Kammer <david.kammer@epfl.ch> * @date Fri Apr 29 11:19:46 2011 * * @brief test restart functions for contact rigid * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -#include <io_helper.h> -#include <reader_restart.h> +#include <io_helper.hh> +#include <reader_restart.hh> +using namespace iohelper; #endif //AKANTU_USE_IOHELPER #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "friction_coefficient.hh" #include "unique_constant_fric_coef.hh" #include "contact_neighbor_structure.hh" #include "regular_grid_neighbor_structure.hh" #include "contact_search.hh" #include "contact_search_explicit.hh" using namespace akantu; void restartReaderInit(ReaderRestart & reader); void loadRestartInformation(ContactRigid * contact, std::map < std::string, VectorBase* > & map); void DumpRestart(SolidMechanicsModel & my_model, std::map < std::string, VectorBase* > & map); void printRestartMap(std::map < std::string, VectorBase* > & map); void printContact(ContactRigid * contact); void freeMap(std::map < std::string, VectorBase* > & map); UInt dim = 2; const ElementType element_type = _triangle_3; -const UInt paraview_type = TRIANGLE1; +const ElemType paraview_type = TRIANGLE1; Surface master; UInt nb_nodes; UInt nb_elements; UInt nb_components; Real * displacement; bool * boundary; std::ofstream test_output; int main(int argc, char *argv[]) { /// define output file for testing std::stringstream filename_sstr; filename_sstr << "test_contact_rigid_restart.out"; test_output.open(filename_sstr.str().c_str()); #ifdef AKANTU_USE_IOHELPER // without iohelper, this restart does not work and therefore the test is useless. #else test_output << "Test does not make sense without iohelper" << std::endl; return EXIT_FAILURE; #endif //AKANTU_USE_IOHELPER debug::setDebugLevel(dblWarning); - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); /// load mesh Mesh my_mesh(dim); MeshIOMSH mesh_io; mesh_io.read("triangle_3.msh", my_mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(my_mesh,1,0); MeshUtils::buildSurfaceID(my_mesh); UInt max_steps = 3; nb_nodes = my_mesh.getNbNodes(); nb_elements = my_mesh.getNbElement(element_type); /// dump facet and surface information to paraview #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(my_mesh.getNodes().values, dim, nb_nodes, "restart_triangle_3"); dumper.SetConnectivity((int*)my_mesh.getConnectivity(element_type).values, TRIANGLE1, my_mesh.getNbElement(element_type), C_MODE); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER /// declaration of model SolidMechanicsModel my_model(my_mesh); /// model initialization my_model.initVectors(); my_model.getForce().clear(); my_model.getVelocity().clear(); my_model.getAcceleration().clear(); my_model.getDisplacement().clear(); displacement = my_model.getDisplacement().values; boundary = my_model.getBoundary().values; my_model.initExplicit(); my_model.initModel(); my_model.readMaterials("material.dat"); my_model.initMaterials(); Real time_step = my_model.getStableTimeStep(); my_model.setTimeStep(time_step/10.); my_model.assembleMassLumped(); /// contact declaration Contact * contact = Contact::newContact(my_model, _ct_rigid, _cst_expli, _cnst_regular_grid); ContactRigid * my_contact = dynamic_cast<ContactRigid *>(contact); my_contact->initContact(false); master = 0; Surface impactor = 1; my_contact->addMasterSurface(master); my_contact->addImpactorSurfaceToMasterSurface(impactor, master); FrictionCoefficient *fric_coef; fric_coef = new UniqueConstantFricCoef(*my_contact, master, 0.1); // contact information ContactRigid::SurfaceToImpactInfoMap::const_iterator it_imp_1; it_imp_1 = my_contact->getImpactorsInformation().find(master); ContactRigid::ImpactorInformationPerMaster * imp_info = it_imp_1->second; nb_components = imp_info->node_is_sticking->getNbComponent(); my_model.updateCurrentPosition(); // neighbor structure uses current position for init my_contact->initNeighborStructure(master); my_contact->initSearch(); // does nothing so far /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ for(UInt s = 1; s <= max_steps; ++s) { std::cout << "passing step " << s << "/" << max_steps << "\r"; std::cout.flush(); /// apply a displacement to the slave body if(s == 2) { Real * coord = my_mesh.getNodes().values; for(UInt n = 0; n < nb_nodes; ++n) { if(coord[n*dim + 0] > 0.5) { displacement[n*dim+0] = -0.02; } } } /// integration with contact and friction my_model.explicitPred(); my_model.initializeUpdateResidualData(); my_contact->solveContact(); my_model.updateResidual(false); my_contact->avoidAdhesion(); my_contact->frictionPredictor(); my_model.updateAcceleration(); my_model.explicitCorr(); my_contact->frictionCorrector(); } std::cout << std::endl; /// print contact info test_output << "CONTACT" << std::endl; printContact(my_contact); /// put restart information into a map std::map < std::string, VectorBase* > output_map; my_contact->getRestartInformation(output_map, master); DumpRestart(my_model, output_map); test_output << "MAP" << std::endl; printRestartMap(output_map); // freeMap(output_map); // ---------------- Reload contact from restart files --------------------- Contact * contact_restart = Contact::newContact(my_model, _ct_rigid, _cst_expli, _cnst_regular_grid, "contact_restart"); ContactRigid * my_contact_restart = dynamic_cast<ContactRigid *>(contact_restart); my_contact_restart->initContact(false); my_contact_restart->addMasterSurface(master); my_contact_restart->addImpactorSurfaceToMasterSurface(impactor, master); std::map < std::string, VectorBase* > input_map; loadRestartInformation(my_contact_restart, input_map); test_output << "RESTART MAP" << std::endl; printRestartMap(input_map); freeMap(input_map); test_output << "RESTART CONTACT" << std::endl; printContact(my_contact_restart); // finalize delete my_contact; delete my_contact_restart; finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ void restartReaderInit(ReaderRestart & reader) { #ifdef AKANTU_USE_IOHELPER reader.SetPoints("restart_test"); reader.SetConnectivity(paraview_type); reader.AddNodeDataField("displacements"); reader.AddNodeDataField("velocities"); reader.AddNodeDataField("accelerations"); reader.AddNodeDataField("forces"); reader.AddNodeDataField("boundaries"); reader.AddNodeDataField("active_impactor_nodes"); reader.AddNodeDataField("master_element_type"); reader.AddNodeDataField("master_normals"); reader.AddNodeDataField("node_is_sticking"); reader.AddNodeDataField("friction_forces"); reader.AddNodeDataField("stick_positions"); reader.AddNodeDataField("residual_forces"); reader.AddNodeDataField("previous_velocities"); reader.SetMode(COMPRESSED); reader.SetPrefix("restart"); reader.Init(); reader.Read(); // test if good number of node (-> good mesh) UInt reader_nb_nodes = reader.GetNumberNodes(); if (reader_nb_nodes != nb_nodes) test_output << "WRONG MESH LOADED !!" << std::endl; #endif //AKANTU_USE_IOHELPER } /* -------------------------------------------------------------------------- */ void loadRestartInformation(ContactRigid * contact, std::map < std::string, VectorBase* > & map) { #ifdef AKANTU_USE_IOHELPER // get the equilibrium state from the restart files ReaderRestart * restart_reader = new ReaderRestart(); restartReaderInit(*restart_reader); memcpy(displacement,restart_reader->GetNodeDataField("displacements"),dim*nb_nodes*sizeof(Real)); Real * tmp_r = restart_reader->GetNodeDataField("boundaries"); Vector<bool> * boundary_r = new Vector<bool>(nb_nodes, dim, false); for (UInt i=0; i<nb_nodes; ++i) { for (UInt j=0; j<dim; ++j) { if(tmp_r[i*dim+j] > 0.01) { (*boundary_r)(i,j) = true; } } } memcpy(boundary, boundary_r->values, dim*nb_nodes*sizeof(bool)); tmp_r = restart_reader->GetNodeDataField("active_impactor_nodes"); Vector<bool> * ai_nodes = new Vector<bool>(nb_nodes, 1, false, "a_imp_nodes"); for (UInt i=0; i<nb_nodes; ++i) { if(tmp_r[i] > 0.01) (*ai_nodes)(i) = true; } map["active_impactor_nodes"] = ai_nodes; tmp_r = restart_reader->GetNodeDataField("master_element_type"); Vector<ElementType> * et_nodes = new Vector<ElementType>(nb_nodes, 1, _not_defined); for (UInt i=0; i<nb_nodes; ++i) { (*et_nodes)(i) = (ElementType)(tmp_r[i]); } map["master_element_type"] = et_nodes; tmp_r = restart_reader->GetNodeDataField("master_normals"); Vector<Real> * mn_nodes = new Vector<Real>(0, dim); for (UInt i=0; i<nb_nodes; ++i) { Real normal[dim]; for (UInt j=0; j<dim; ++j) { normal[j] = tmp_r[i*dim+j]; } mn_nodes->push_back(normal); } map["master_normals"] = mn_nodes; tmp_r = restart_reader->GetNodeDataField("node_is_sticking"); Vector<bool> * is_nodes = new Vector<bool>(nb_nodes, nb_components, false); for (UInt i=0; i<nb_nodes; ++i) { for (UInt j=0; j<nb_components; ++j) { if(tmp_r[i*nb_components+j] > 0.01) (*is_nodes)(i,j) = true; } } map["node_is_sticking"] = is_nodes; tmp_r = restart_reader->GetNodeDataField("friction_forces"); Vector<Real> * ff_nodes = new Vector<Real>(0, dim); for (UInt i=0; i<nb_nodes; ++i) { Real normal[dim]; for (UInt j=0; j<dim; ++j) { normal[j] = tmp_r[i*dim+j]; } ff_nodes->push_back(normal); } map["friction_forces"] = ff_nodes; tmp_r = restart_reader->GetNodeDataField("stick_positions"); Vector<Real> * sp_nodes = new Vector<Real>(0, dim); for (UInt i=0; i<nb_nodes; ++i) { Real position[dim]; for (UInt j=0; j<dim; ++j) { position[j] = tmp_r[i*dim+j]; } sp_nodes->push_back(position); } map["stick_positions"] = sp_nodes; tmp_r = restart_reader->GetNodeDataField("residual_forces"); Vector<Real> * rf_nodes = new Vector<Real>(0, dim); for (UInt i=0; i<nb_nodes; ++i) { Real resid[dim]; for (UInt j=0; j<dim; ++j) { resid[j] = tmp_r[i*dim+j]; } rf_nodes->push_back(resid); } map["residual_forces"] = rf_nodes; tmp_r = restart_reader->GetNodeDataField("previous_velocities"); Vector<Real> * pv_nodes = new Vector<Real>(0, dim); for (UInt i=0; i<nb_nodes; ++i) { Real pr_vel[dim]; for (UInt j=0; j<dim; ++j) { pr_vel[j] = tmp_r[i*dim+j]; } pv_nodes->push_back(pr_vel); } map["previous_velocities"] = pv_nodes; contact->setRestartInformation(map, master); delete boundary_r; // delete ai_nodes; // delete et_nodes; // delete mn_nodes; // delete is_nodes; // delete ff_nodes; // delete sp_nodes; // delete rf_nodes; // delete pv_nodes; delete restart_reader; #endif //AKANTU_USE_IOHELPER } /* -------------------------------------------------------------------------- */ void DumpRestart(SolidMechanicsModel & my_model, std::map < std::string, VectorBase* > & map) { #ifdef AKANTU_USE_IOHELPER DumperRestart dumper; dumper.SetPoints(my_model.getFEM().getMesh().getNodes().values, dim,nb_nodes,"restart_test"); dumper.SetConnectivity((int *)my_model.getFEM().getMesh().getConnectivity(element_type).values, paraview_type, nb_elements, C_MODE); dumper.AddNodeDataField(my_model.getDisplacement().values, dim, "displacements"); dumper.AddNodeDataField(my_model.getVelocity().values, dim, "velocities"); dumper.AddNodeDataField(my_model.getAcceleration().values ,dim, "accelerations"); dumper.AddNodeDataField(my_model.getResidual().values, dim, "forces"); Vector<Real> * boundary_r = new Vector<Real>(nb_nodes, dim, 0.); for (UInt i=0; i<nb_nodes; ++i) { for (UInt j=0; j<dim; ++j) { if (boundary[i*dim+j]) { (*boundary_r)(i,j) = 1.; } } } dumper.AddNodeDataField(boundary_r->values, dim, "boundaries"); // contact information std::map < std::string, VectorBase* >::iterator it; it = map.find("active_impactor_nodes"); Vector<bool> * tmp_vec_b = (Vector<bool> *)(it->second); Vector<Real> * active_impactor_nodes = new Vector<Real>(nb_nodes, 1, 0.); for (UInt i=0; i<nb_nodes; ++i) { if((*tmp_vec_b)(i)) (*active_impactor_nodes)(i) = 1.; } dumper.AddNodeDataField(active_impactor_nodes->values, 1, "active_impactor_nodes"); it = map.find("master_element_type"); Vector<ElementType> * tmp_vec_t = (Vector<ElementType> *)(it->second); Vector<Real> * master_element_type = new Vector<Real>(nb_nodes, 1, (Real)_not_defined); for (UInt i=0; i<nb_nodes; ++i) { (*master_element_type)(i) = (Real)((*tmp_vec_t)(i)); } dumper.AddNodeDataField(master_element_type->values, 1, "master_element_type"); it = map.find("master_normals"); dumper.AddNodeDataField(((Vector<Real> *)it->second)->values, dim, "master_normals"); it = map.find("node_is_sticking"); tmp_vec_b = (Vector<bool> *)(it->second); Vector<Real> * node_is_sticking = new Vector<Real>(nb_nodes, 2, 0.); for (UInt i=0; i<nb_nodes; ++i) { for (UInt j=0; j<2; ++j) { if((*tmp_vec_b)(i,j)) (*node_is_sticking)(i,j) = 1.; } } dumper.AddNodeDataField(node_is_sticking->values, 2, "node_is_sticking"); it = map.find("friction_forces"); dumper.AddNodeDataField(((Vector<Real> *)it->second)->values, dim, "friction_forces"); it = map.find("stick_positions"); dumper.AddNodeDataField(((Vector<Real> *)it->second)->values, dim, "stick_positions"); it = map.find("residual_forces"); dumper.AddNodeDataField(((Vector<Real> *)it->second)->values, dim, "residual_forces"); it = map.find("previous_velocities"); dumper.AddNodeDataField(((Vector<Real> *)it->second)->values, dim, "previous_velocities"); dumper.SetMode(COMPRESSED); dumper.SetPrefix("restart"); dumper.Init(); dumper.Dump(); delete boundary_r; delete active_impactor_nodes; delete master_element_type; delete node_is_sticking; #endif //AKANTU_USE_IOHELPER } /* -------------------------------------------------------------------------- */ void printRestartMap(std::map < std::string, VectorBase* > & map) { /// access all vectors in the map std::map < std::string, VectorBase* >::iterator it; it = map.find("active_impactor_nodes"); Vector<bool> * ai_nodes = dynamic_cast<Vector<bool> *>(it->second); if(it == map.end()) { test_output << "could not find map entry for active impactor nodes" << std::endl; } it = map.find("master_element_type"); Vector<ElementType> * et_nodes = dynamic_cast<Vector<ElementType> *>(it->second); if(it == map.end()) { test_output << "could not find map entry master element type" << std::endl; } it = map.find("master_normals"); Vector<Real> * mn_nodes = dynamic_cast<Vector<Real> *>(it->second); if(it == map.end()) { test_output << "could not find map entry for master normals" << std::endl; } it = map.find("node_is_sticking"); Vector<bool> * is_nodes = dynamic_cast<Vector<bool> *>(it->second); if(it == map.end()) { test_output << "could not find map entry node is sticking" << std::endl; } it = map.find("friction_forces"); Vector<Real> * ff_nodes = dynamic_cast<Vector<Real> *>(it->second); if(it == map.end()) { test_output << "could not find map entry friction forces" << std::endl; } it = map.find("stick_positions"); Vector<Real> * sp_nodes = dynamic_cast<Vector<Real> *>(it->second); if(it == map.end()) { test_output << "could not find map entry stick positions" << std::endl; } it = map.find("residual_forces"); Vector<Real> * rf_nodes = dynamic_cast<Vector<Real> *>(it->second); if(it == map.end()) { test_output << "could not find map entry residual forces" << std::endl; } it = map.find("previous_velocities"); Vector<Real> * pv_nodes = dynamic_cast<Vector<Real> *>(it->second); if(it == map.end()) { test_output << "could not find map entry previous velocities" << std::endl; } /// print all information in restart map test_output << "Active impactor nodes (map):" << std::endl << std::endl; for (UInt i=0; i<nb_nodes; ++i) { if ((*ai_nodes)(i)) { test_output << "node: " << i << ", master element type: " << (*et_nodes)(i) << std::endl; for (UInt d=0; d<dim; ++d) { test_output << "Direction " << d << std::endl; test_output << " master normal = " << (*mn_nodes)(i,d) << std::endl; test_output << " friction force = " << (*ff_nodes)(i,d) << std::endl; test_output << " stick position = " << (*sp_nodes)(i,d) << std::endl; test_output << " residual force = " << (*rf_nodes)(i,d) << std::endl; test_output << " previous velocity = " << (*pv_nodes)(i,d) << std::endl; } for (UInt j=0; j<2; ++j) { test_output << "stick " << j << ": " << (*is_nodes)(i,j) << std::endl; } test_output << std::endl; } } } /* -------------------------------------------------------------------------- */ void printContact(ContactRigid * contact) { ContactRigid::SurfaceToImpactInfoMap::const_iterator it_imp; it_imp = contact->getImpactorsInformation().find(master); ContactRigid::ImpactorInformationPerMaster * impactor_info = it_imp->second; UInt * active_nodes = impactor_info->active_impactor_nodes->values; ElementType * element_type_imp = &(*impactor_info->master_element_type)[0]; Real * master_normal = impactor_info->master_normals->values; bool * node_stick = impactor_info->node_is_sticking->values; Real * friction_force = impactor_info->friction_forces->values; Real * stick_position = impactor_info->stick_positions->values; Real * residual_force = impactor_info->residual_forces->values; Real * previous_velocity = impactor_info->previous_velocities->values; UInt nb_active_nodes = impactor_info->active_impactor_nodes->getSize(); test_output << "Active impactor nodes (contact):" << std::endl << std::endl; for (UInt i=0; i<nb_active_nodes; ++i, ++active_nodes, ++element_type_imp) { test_output << "node: " << (*active_nodes) << ", master element type: " << *element_type_imp << std::endl; for (UInt d=0; d<dim; ++d, ++master_normal, ++friction_force, ++stick_position, ++residual_force, ++previous_velocity) { test_output << "Direction " << d << std::endl; test_output << " master normal = " << *master_normal << std::endl; test_output << " friction force = " << *friction_force << std::endl; test_output << " stick position = " << *stick_position << std::endl; test_output << " residual force = " << *residual_force << std::endl; test_output << " previous velocity = " << *previous_velocity << std::endl; } for (UInt j=0; j<2; ++j, ++node_stick) { test_output << "stick " << j << ": " << *node_stick << std::endl; } test_output << std::endl; } } /* -------------------------------------------------------------------------- */ void freeMap(std::map < std::string, VectorBase* > & map) { std::map < std::string, VectorBase* >::iterator it = map.begin(); std::map < std::string, VectorBase* >::iterator end = map.end(); for (; it != end; ++it) { delete it->second; } } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_single_spring_friction_vel_weak_exp.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_single_spring_friction_vel_weak_exp.cc index cd742b24d..7cea9ec6a 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_single_spring_friction_vel_weak_exp.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_rigid/test_single_spring_friction_vel_weak_exp.cc @@ -1,507 +1,508 @@ /** * @file test_single_spring_friction_vel_weak_exp.cc * @author David Kammer <david.kammer@epfl.ch> * @date Mon Oct 17 16:18:55 2011 * * @brief test friction of exponential velocity weakening law (not with analytical solution) * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <stdio.h> #include <stdlib.h> #ifdef AKANTU_USE_IOHELPER -#include <io_helper.h> +#include <io_helper.hh> +using namespace iohelper; #endif //AKANTU_USE_IOHELPER #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "friction_coefficient.hh" #include "velocity_weakening_coulomb.hh" #include "velocity_weakening_exponential.hh" #include "contact_neighbor_structure.hh" #include "regular_grid_neighbor_structure.hh" #include "contact_search.hh" #include "contact_search_explicit.hh" using namespace akantu; /* -------------------------------------------------------------------------- */ Surface impactor = 0; Surface master = 1; UInt the_node = 0; const ElementType element_type = _triangle_3; #ifdef AKANTU_USE_IOHELPER -const UInt paraview_type = TRIANGLE1; +const ElemType paraview_type = TRIANGLE1; #endif //AKANTU_USE_IOHELPER const char* mesh_name = "single_triangle.msh"; const char* folder_name = "single_spring_friction_vel_weak_exp"; std::string result_name; Real mu_s = 0.3; Real mu_d = 0.2; Real power = 1.; const UInt paraview_dump_int = 1e1; const UInt file_dump_int = 1e1; const UInt max_steps = 1e6; const UInt stick_stop = 3; Real n_k = 0.15; Real normal_force; Real start_displacement = 0.2; Mesh * mesh; SolidMechanicsModel * model; UInt spatial_dimension = 2; Real time_step_security = 3.; Real time_step; UInt nb_nodes; UInt nb_elements; UInt stick_counter = 0; bool patch_test = false; const Real tolerance = std::numeric_limits<Real>::epsilon() * 10.; // variables of model Real * coordinates; Real * displacement; Real * current_position; Real * velocity; Real * residual; Real * acceleration; bool * boundary; Real * force; Real * mass; std::map < std::string, VectorBase* > restart_map; #ifdef AKANTU_USE_IOHELPER void paraviewInit(Dumper & dumper); #endif //AKANTU_USE_IOHELPER void loadRestartInformation(ContactRigid * contact); void printPredictor(UInt step, std::ofstream & out_stream); void printCorrector(UInt step, ContactRigid * contact, std::ofstream & out_stream); void getStickInfo(ContactRigid * contact); bool testFloat(Real a, Real b, Real adm_error); /* -------------------------------------------------------------------------- */ Int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); debug::setDebugLevel(dblWarning); // 1: name // 2: initial displacement // 3: static friction coefficient // 4: dynamic friction coefficient // 5: power // 6: ratio N/K with N normal force & K stiffness if (argc == 7) { result_name = argv[1]; start_displacement = atof(argv[2]); mu_s = atof(argv[3]); mu_d = atof(argv[4]); power = atof(argv[5]); n_k = atof(argv[6]); } else { result_name = "patch_test_output"; patch_test = true; // return EXIT_FAILURE; } /// load mesh mesh = new Mesh(spatial_dimension); MeshIOMSH mesh_io; mesh_io.read(mesh_name, *mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(*mesh,1,0); MeshUtils::buildSurfaceID(*mesh); /// declaration of model model = new SolidMechanicsModel(*mesh); nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_elements = model->getFEM().getMesh().getNbElement(element_type); std::cout << "Nb nodes : " << nb_nodes << " - nb elements : " << nb_elements << std::endl; /// model initialization model->initVectors(); // initialize the vectors model->getForce().clear(); model->getVelocity().clear(); model->getAcceleration().clear(); model->getDisplacement().clear(); model->initExplicit(); model->initModel(); /// read and initialize material model->readMaterials("material.dat"); model->initMaterials(); Real stable_time_step = model->getStableTimeStep(); time_step = stable_time_step/time_step_security; model->setTimeStep(time_step); std::cout << "The time step is " << time_step << std::endl; // accessors to model elements coordinates = mesh->getNodes().values; displacement = model->getDisplacement().values; velocity = model->getVelocity().values; acceleration = model->getAcceleration().values; boundary = model->getBoundary().values; residual = model->getResidual().values; model->updateCurrentPosition(); current_position = model->getCurrentPosition().values; force = model->getForce().values; mass = model->getMass().values; model->assembleMassLumped(); UInt nb_surfaces = mesh->getNbSurfaces(); nb_surfaces += 1; /// contact declaration Contact * contact_structure = Contact::newContact(*model, _ct_rigid, _cst_expli, _cnst_regular_grid); ContactRigid * contact = dynamic_cast<ContactRigid *>(contact_structure); //contact->initContact(false); contact->addMasterSurface(master); contact->addImpactorSurfaceToMasterSurface(impactor, master); /// define the friction law FrictionCoefficient *fric_coef; fric_coef = new VelocityWeakeningExponential(*contact, master, mu_s, mu_d, power); // load restart file loadRestartInformation(contact); // set boundary condition displacement[the_node*spatial_dimension] = start_displacement; model->updateCurrentPosition(); model->updateResidual(); Real stiffness = std::abs(residual[the_node * spatial_dimension] / start_displacement); normal_force = n_k * stiffness; force[the_node*spatial_dimension+1] = -normal_force; if (start_displacement > tolerance) { std::cout << "Start displacement = " << start_displacement << " ; Residual = " << residual[the_node*spatial_dimension] << " -> Stiffness K = " << stiffness << std::endl; std::cout << "Mass = " << mass[the_node] << std::endl; } else std::cout << "No start displacement!! " << std::endl; /// initialize the paraview output #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; #endif //AKANTU_USE_IOHELPER std::ofstream out_info; if (!patch_test) { model->updateResidual(); #ifdef AKANTU_USE_IOHELPER paraviewInit(dumper); #endif //AKANTU_USE_IOHELPER /// output files std::stringstream name_info; name_info << "output_files/" << folder_name << "/global_info.dat"; out_info.open(name_info.str().c_str()); out_info << "%id time fnorm fres ffric ftot mu disp vel stick ekin epot etot" << std::endl; } UInt step = 0; Real previous_vel = 0.; UInt count_cycle = 0; /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ while(stick_counter <= stick_stop && step <= max_steps) { // increase step step += 1; if(step % 1000 == 0) { std::cout << "passing step " << step << "/" << max_steps << "\r"; std::cout.flush(); } model->explicitPred(); model->updateResidual(); if (step % file_dump_int == 0 && !patch_test) printPredictor(step, out_info); contact->frictionPredictor(); model->updateAcceleration(); model->explicitCorr(); contact->frictionCorrector(); // see if node sticks getStickInfo(contact); // count numbers of cycles if (Math::are_float_equal(velocity[the_node * spatial_dimension], 0.) && !Math::are_float_equal(previous_vel, 0.)) count_cycle++; previous_vel = velocity[the_node * spatial_dimension]; if(step % file_dump_int == 0 && !patch_test) printCorrector(step, contact, out_info); #ifdef AKANTU_USE_IOHELPER if(step % paraview_dump_int == 0 && !patch_test) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } std::cout << "passing step " << step << "/" << max_steps << std::endl; Real final_displacement = displacement[the_node * spatial_dimension]; // check patch test if(patch_test) { Real correct_final_disp = -0.0200196; Real admissible_error = 1e-07; UInt correct_nb_cycle = 3; //if (!(Math::are_float_equal(final_displacement, correct_final_disp)) | !(count_cycle == correct_nb_cycle)) { if (!(testFloat(final_displacement, correct_final_disp, admissible_error)) | !(count_cycle == correct_nb_cycle)) { std::cout << "Final displacement is " << final_displacement << ", which should be " << correct_final_disp << std::endl; std::cout << "Final number of cycles is " << count_cycle << ", which should be " << correct_nb_cycle << std::endl; return EXIT_FAILURE; } else { std::cout << "Patch test successful!" << std::endl; return EXIT_SUCCESS; } } else { /// output files std::stringstream result_name_path; result_name_path << "output_files/" << folder_name << "/" << result_name << ".dat"; std::ofstream out_result; out_result.open(result_name_path.str().c_str(), std::ios::app); if (!out_result.good()) { std::cout << "Could not open result file " << std::endl; return EXIT_FAILURE; } out_result << start_displacement << " " << final_displacement << " " << count_cycle << std::endl; out_result.close(); } out_info.close(); delete fric_coef; delete contact; delete model; delete mesh; finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER void paraviewInit(Dumper & dumper) { std::stringstream name; name << "paraview/" << folder_name << "/"; dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(element_type).values, paraview_type, nb_elements, C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model->getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model->getMass().values, 1, "mass"); dumper.AddNodeDataField(model->getForce().values, spatial_dimension, "applied_force"); dumper.AddElemDataField(model->getMaterial(0).getStrain(element_type).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(element_type).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix(name.str().c_str()); dumper.Init(); dumper.Dump(); } #endif //AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ void loadRestartInformation(ContactRigid * contact) { // boundary conditions Vector<bool> * boundary_r = new Vector<bool>(nb_nodes, spatial_dimension, false); // sticked nodes (*boundary_r)(1,0) = true; (*boundary_r)(1,1) = true; (*boundary_r)(2,0) = true; (*boundary_r)(2,1) = true; // the impactor node (*boundary_r)(0,1) = true; memcpy(boundary, boundary_r->values, spatial_dimension*nb_nodes*sizeof(bool)); // set the active impactor node Vector<bool> * ai_nodes = new Vector<bool>(nb_nodes, 1, false); (*ai_nodes)(the_node) = true; restart_map["active_impactor_nodes"] = ai_nodes; // not defined master type, because won't use solve contact Vector<ElementType> * et_nodes = new Vector<ElementType>(nb_nodes, 1, _not_defined); restart_map["master_element_type"] = et_nodes; // master normal x=0; y=1 Vector<Real> * mn_nodes = new Vector<Real>(0, spatial_dimension); Real normal[spatial_dimension]; normal[0] = 0.; normal[1] = 1.; mn_nodes->push_back(normal); restart_map["master_normals"] = mn_nodes; // node is sticking Vector<bool> * is_nodes = new Vector<bool>(nb_nodes, 2, false); (*is_nodes)(0,0) = true; (*is_nodes)(0,1) = true; restart_map["node_is_sticking"] = is_nodes; // no friction force Vector<Real> * ff_nodes = new Vector<Real>(0, spatial_dimension); Real force[spatial_dimension]; force[0] = 0.; force[1] = 0.; ff_nodes->push_back(force); restart_map["friction_forces"] = ff_nodes; // the original stick position (for regularized friction) Vector<Real> * sp_nodes = new Vector<Real>(0, spatial_dimension); Real position[spatial_dimension]; position[0] = 0.; position[1] = 0.; sp_nodes->push_back(position); restart_map["stick_positions"] = sp_nodes; // no residual forces Vector<Real> * rf_nodes = new Vector<Real>(0, spatial_dimension); Real r_force[spatial_dimension]; r_force[0] = 0.; r_force[1] = 0.; rf_nodes->push_back(r_force); restart_map["residual_forces"] = rf_nodes; // no previous velocities Vector<Real> * pv_nodes = new Vector<Real>(0, spatial_dimension); Real vel[spatial_dimension]; vel[0] = 0.; vel[1] = 0.; pv_nodes->push_back(vel); restart_map["previous_velocities"] = pv_nodes; contact->setRestartInformation(restart_map, master); delete boundary_r; delete ai_nodes; delete et_nodes; delete mn_nodes; delete is_nodes; delete ff_nodes; delete sp_nodes; delete rf_nodes; delete pv_nodes; } /* -------------------------------------------------------------------------- */ void printPredictor(UInt step, std::ofstream & out_stream) { out_stream << step << " " << step*time_step << " " << residual[the_node*spatial_dimension + 1] << " " << residual[the_node * spatial_dimension]; } /* -------------------------------------------------------------------------- */ void printCorrector(UInt step, ContactRigid * contact, std::ofstream & out_stream) { Real epot = model->getPotentialEnergy(); Real ekin = model->getKineticEnergy(); // find index of master surface in impactors_information ContactRigid::SurfaceToImpactInfoMap::const_iterator it_imp; it_imp = contact->getImpactorsInformation().find(master); // find the total contact force and contact area ContactRigid::ImpactorInformationPerMaster * imp_info = it_imp->second; Real * friction_forces_val = imp_info->friction_forces->values; bool * sticking_nodes_val = imp_info->node_is_sticking->values; out_stream << " " << friction_forces_val[0] << " " << residual[the_node * spatial_dimension] << " " << friction_forces_val[0] / residual[the_node * spatial_dimension + 1] << " " << displacement[the_node * spatial_dimension] << " " << velocity[the_node * spatial_dimension] << " " << sticking_nodes_val[0] << " " << ekin << " " << epot << " " << ekin+epot << std::endl; if (sticking_nodes_val[0]) stick_counter++; else stick_counter = 0; } /* -------------------------------------------------------------------------- */ void getStickInfo(ContactRigid * contact) { // find index of master surface in impactors_information ContactRigid::SurfaceToImpactInfoMap::const_iterator it_imp; it_imp = contact->getImpactorsInformation().find(master); // find the total contact force and contact area ContactRigid::ImpactorInformationPerMaster * imp_info = it_imp->second; bool * sticking_nodes_val = imp_info->node_is_sticking->values; if (sticking_nodes_val[the_node*2]) stick_counter++; else stick_counter = 0; } /* -------------------------------------------------------------------------- */ bool testFloat(Real a, Real b, Real adm_error) { if (fabs(a-b) < adm_error) return true; else return false; } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/io_helper_tools.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/io_helper_tools.cc index d7d55e1ea..4b673f843 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/io_helper_tools.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/io_helper_tools.cc @@ -1,294 +1,294 @@ /** * @file io_helper_tools.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Sep 30 11:13:01 2011 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "io_helper_tools.hh" #include "aka_common.hh" #include "mesh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "static_communicator.hh" // #include "dof_synchronizer.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; /* ------------------------------------------------------------------------ */ template <ElementType type> -static UInt getIOHelperType() { AKANTU_DEBUG_TO_IMPLEMENT(); return -1; }; - -template <> UInt getIOHelperType<_segment_2>() { return LINE1; } -template <> UInt getIOHelperType<_segment_3>() { return LINE2; } -template <> UInt getIOHelperType<_triangle_3>() { return TRIANGLE1; } -template <> UInt getIOHelperType<_triangle_6>() { return TRIANGLE2; } -template <> UInt getIOHelperType<_quadrangle_4>() { return QUAD1; } -template <> UInt getIOHelperType<_quadrangle_8>() { return QUAD2; } -template <> UInt getIOHelperType<_tetrahedron_4>() { return TETRA1; } -template <> UInt getIOHelperType<_tetrahedron_10>() { return TETRA2; } -template <> UInt getIOHelperType<_hexahedron_8>() { return HEX1; } - -static UInt getIOHelperType(ElementType type) { - UInt ioh_type = -1; +static ElemType getIOHelperType() { AKANTU_DEBUG_TO_IMPLEMENT(); return MAX_ELEM_TYPE; }; + +template <> ElemType getIOHelperType<_segment_2>() { return LINE1; } +template <> ElemType getIOHelperType<_segment_3>() { return LINE2; } +template <> ElemType getIOHelperType<_triangle_3>() { return TRIANGLE1; } +template <> ElemType getIOHelperType<_triangle_6>() { return TRIANGLE2; } +template <> ElemType getIOHelperType<_quadrangle_4>() { return QUAD1; } +template <> ElemType getIOHelperType<_quadrangle_8>() { return QUAD2; } +template <> ElemType getIOHelperType<_tetrahedron_4>() { return TETRA1; } +template <> ElemType getIOHelperType<_tetrahedron_10>() { return TETRA2; } +template <> ElemType getIOHelperType<_hexahedron_8>() { return HEX1; } + +static ElemType getIOHelperType(ElementType type) { + ElemType ioh_type; #define GET_IOHELPER_TYPE(type) \ ioh_type = getIOHelperType<type>(); AKANTU_BOOST_ELEMENT_SWITCH(GET_IOHELPER_TYPE); #undef GET_IOHELPER_TYPE return ioh_type; } /* ------------------------------------------------------------------------ */ void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model, const ElementType & type, const std::string & filename) { const Mesh & mesh = model.getFEM().getMesh(); UInt spatial_dimension = mesh.getSpatialDimension(type); UInt nb_nodes = mesh.getNbNodes(); UInt nb_element = mesh.getNbElement(type); std::stringstream filename_sstr; filename_sstr << filename << "_" << type; UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); UInt nproc = StaticCommunicator::getStaticCommunicator()->getNbProc(); dumper.SetMode(TEXT); dumper.SetParallelContext(whoami, nproc); dumper.SetPoints(mesh.getNodes().values, spatial_dimension, nb_nodes, filename_sstr.str().c_str()); dumper.SetConnectivity((int *)mesh.getConnectivity(type).values, getIOHelperType(type), nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model.getAcceleration().values, spatial_dimension, "acceleration"); dumper.AddNodeDataField(model.getMass().values, spatial_dimension, "mass"); dumper.AddNodeDataField(model.getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model.getForce().values, spatial_dimension, "applied_force"); dumper.AddElemDataField(model.getMaterial(0).getStrain(type).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model.getMaterial(0).getStress(type).values, spatial_dimension*spatial_dimension, "stress"); if(dynamic_cast<const MaterialDamage *>(&model.getMaterial(0))) { const MaterialDamage & mat = dynamic_cast<const MaterialDamage &>(model.getMaterial(0)); Real * dam = mat.getDamage(type).storage(); dumper.AddElemDataField(dam, 1, "damage"); } dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* ------------------------------------------------------------------------ */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ // Vector<Real> checkpoint_displacements(0, spatial_dimension); // Vector<Real> checkpoint_velocity(0, spatial_dimension); // Vector<Real> checkpoint_acceleration(0, spatial_dimension); // Vector<Real> checkpoint_force(0, spatial_dimension); // /* ------------------------------------------------------------------------ */ // void checkpointInit(Dumper & dumper, // const SolidMechanicsModel & model, // const ElementType & type, // const std::string & filename) { // UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); // UInt nproc = StaticCommunicator::getStaticCommunicator()->getNbProc(); // Vector<Real> & displacements = model.getDisplacement(); // Vector<Real> & velocity = model.getVelocity(); // Vector<Real> & acceleration = model.getAcceleration(); // Vector<Real> & force = model.getForce(); // DOFSynchronizer & dof_synchronizer = const_cast<DOFSynchronizer &>(model.getDOFSynchronizer()); // dof_synchronizer.initScatterGatherCommunicationScheme(); // if(whoami == 0){ // const Mesh & mesh = model.getFEM().getMesh(); // UInt nb_nodes = mesh.getNbGlobalNodes(); // checkpoint_displacements.resize(nb_nodes); // checkpoint_velocity .resize(nb_nodes); // checkpoint_acceleration .resize(nb_nodes); // checkpoint_force .resize(nb_nodes); // dof_synchronizer.gather(displacements, 0, &checkpoint_displacements); // dof_synchronizer.gather(velocity , 0, &checkpoint_velocity ); // dof_synchronizer.gather(acceleration , 0, &checkpoint_acceleration ); // dof_synchronizer.gather(force , 0, &checkpoint_force ); // UInt nb_element = mesh.getNbElement(type); // UInt spatial_dimension = mesh.getSpatialDimension(type); // std::stringstream filename_sstr; filename_sstr << filename << "_" << type; // dumper.SetMode(COMPRESSED); // dumper.SetParallelContext(whoami, nproc); // dumper.SetPoints(mesh.getNodes().values, // spatial_dimension, nb_nodes, filename_sstr.str().c_str()); // dumper.SetConnectivity((int *)mesh.getConnectivity(type).values, // getIOHelperType(type), nb_element, C_MODE); // dumper.AddNodeDataField(checkpoint_displacements.storage(), spatial_dimension, "displacements"); // dumper.AddNodeDataField(checkpoint_velocity .storage(), spatial_dimension, "velocity"); // dumper.AddNodeDataField(checkpoint_acceleration .storage(), spatial_dimension, "acceleration"); // dumper.AddNodeDataField(checkpoint_force .storage(), spatial_dimension, "applied_force"); // dumper.SetPrefix("restart/"); // dumper.Init(); // dumper.Dump(); // } else { // dof_synchronizer.gather(displacements, 0); // dof_synchronizer.gather(velocity , 0); // dof_synchronizer.gather(acceleration , 0); // dof_synchronizer.gather(force , 0); // } // } // /* ------------------------------------------------------------------------ */ // void checkpoint(Dumper & dumper, // const SolidMechanicsModel & model) { // UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); // DOFSynchronizer & dof_synchronizer = const_cast<DOFSynchronizer &>(model.getDOFSynchronizer()); // Vector<Real> & displacements = model.getDisplacement(); // Vector<Real> & velocity = model.getVelocity(); // Vector<Real> & acceleration = model.getAcceleration(); // Vector<Real> & force = model.getForce(); // if(whoami == 0){ // dof_synchronizer.gather(displacements, 0, &checkpoint_displacements); // dof_synchronizer.gather(velocity , 0, &checkpoint_velocity ); // dof_synchronizer.gather(acceleration , 0, &checkpoint_acceleration ); // dof_synchronizer.gather(force , 0, &checkpoint_force ); // dumper.Dump(); // } else { // dof_synchronizer.gather(displacements, 0); // dof_synchronizer.gather(velocity , 0); // dof_synchronizer.gather(acceleration , 0); // dof_synchronizer.gather(force , 0); // } // } // /* ------------------------------------------------------------------------ */ // /* ------------------------------------------------------------------------ */ // void restart(const SolidMechanicsModel & model, // const ElementType & type, // const std::string & filename) { // UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); // UInt nproc = StaticCommunicator::getStaticCommunicator()->getNbProc(); // DOFSynchronizer & dof_synchronizer = const_cast<DOFSynchronizer &>(model.getDOFSynchronizer()); // dof_synchronizer.initScatterGatherCommunicationScheme(); // Vector<Real> & displacements = model.getDisplacement(); // Vector<Real> & velocity = model.getVelocity(); // Vector<Real> & acceleration = model.getAcceleration(); // Vector<Real> & force = model.getForce(); // if(whoami == 0){ // const Mesh & mesh = model.getFEM().getMesh(); // UInt nb_nodes = mesh.getNbGlobalNodes(); // UInt spatial_dimension = mesh.getSpatialDimension(type); // std::stringstream filename_sstr; filename_sstr << filename << "_" << type; // ReaderRestart reader; // reader.SetMode(COMPRESSED); // reader.SetParallelContext(whoami, nproc); // reader.SetPoints(filename_sstr.str().c_str()); // reader.SetConnectivity(getIOHelperType(type)); // reader.AddNodeDataField("displacements"); // reader.AddNodeDataField("velocity"); // reader.AddNodeDataField("acceleration"); // reader.AddNodeDataField("applied_force"); // reader.SetPrefix("restart/"); // reader.Init(); // reader.Read(); // Vector<Real> restart_tmp_vect(nb_nodes, spatial_dimension); // displacements.clear(); // velocity.clear(); // acceleration.clear(); // force.clear(); // Real * tmp = reader.GetNodeDataField("displacements"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(displacements, 0, &restart_tmp_vect); // tmp = reader.GetNodeDataField("velocity"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(velocity , 0, &restart_tmp_vect); // tmp = reader.GetNodeDataField("acceleration"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(acceleration , 0, &restart_tmp_vect); // tmp = reader.GetNodeDataField("applied_force"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(force , 0, &restart_tmp_vect); // } else { // displacements.clear(); // velocity.clear(); // acceleration.clear(); // force.clear(); // dof_synchronizer.scatter(displacements, 0); // dof_synchronizer.scatter(velocity , 0); // dof_synchronizer.scatter(acceleration , 0); // dof_synchronizer.scatter(force , 0); // } // } /* ------------------------------------------------------------------------ */ diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/io_helper_tools.hh b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/io_helper_tools.hh index f9098b366..13d22c486 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/io_helper_tools.hh +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/io_helper_tools.hh @@ -1,53 +1,54 @@ /** * @file io_helper_tools.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Sep 30 11:15:18 2011 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "solid_mechanics_model.hh" -#include "io_helper.h" +#include "io_helper.hh" +using namespace iohelper; extern const akantu::UInt spatial_dimension; /* ------------------------------------------------------------------------ */ void paraviewInit(Dumper & dumper, const akantu::SolidMechanicsModel & model, const akantu::ElementType & type, const std::string & filename); void paraviewDump(Dumper & dumper); // void checkpointInit(Dumper & dumper, // const akantu::SolidMechanicsModel & model, // const akantu::ElementType & type, // const std::string & filename); // void checkpoint(Dumper & dumper, // const akantu::SolidMechanicsModel & model); // void restart(const akantu::SolidMechanicsModel & model, // const akantu::ElementType & type, // const std::string & filename); diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/test_contact_search_explicit.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/test_contact_search_explicit.cc index 22bde571b..001cfbe10 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/test_contact_search_explicit.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_contact_search/test_contact_search_explicit/test_contact_search_explicit.cc @@ -1,219 +1,219 @@ /** * @file test_contact_search_explicit.cc * @author David Kammer <david.kammer@epfl.ch> * @date Fri Oct 7 16:15:48 2011 * * @brief test contact search for all types * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "contact_neighbor_structure.hh" #include "regular_grid_neighbor_structure.hh" #include "contact_search.hh" #include "contact_search_explicit.hh" #ifdef AKANTU_USE_IOHELPER # include "io_helper_tools.hh" #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); debug::setDebugLevel(dblWarning); const ElementType element_type = TYPE; UInt dim = Mesh::getSpatialDimension(element_type); /// load mesh Mesh my_mesh(dim); MeshIOMSH mesh_io; std::stringstream meshname_sstr; meshname_sstr << element_type << ".msh"; mesh_io.read(meshname_sstr.str().c_str(), my_mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(my_mesh,1,0); MeshUtils::buildSurfaceID(my_mesh); UInt max_steps = 3; unsigned int nb_nodes = my_mesh.getNbNodes(); /// declaration of model SolidMechanicsModel my_model(my_mesh); /// model initialization my_model.initVectors(); my_model.getForce().clear(); my_model.getVelocity().clear(); my_model.getAcceleration().clear(); my_model.getDisplacement().clear(); Real * displacement = my_model.getDisplacement().values; my_model.initExplicit(); my_model.initModel(); my_model.readMaterials("material.dat"); my_model.initMaterials(); /// dump facet and surface information to paraview #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper, my_model, element_type, "para"); #endif //AKANTU_USE_IOHELPER Real time_step = my_model.getStableTimeStep(); my_model.setTimeStep(time_step/10.); my_model.assembleMassLumped(); /// contact declaration Contact * contact = Contact::newContact(my_model, _ct_rigid, _cst_expli, _cnst_regular_grid); ContactRigid * my_contact = dynamic_cast<ContactRigid *>(contact); my_contact->initContact(false); Surface master = 0; Surface impactor = 1; my_contact->addMasterSurface(master); my_contact->addImpactorSurfaceToMasterSurface(impactor, master); my_model.updateCurrentPosition(); // neighbor structure uses current position for init my_contact->initNeighborStructure(master); /// define output file for testing std::stringstream filename_sstr; filename_sstr << "test_contact_search_explicit_" << element_type << ".out"; std::ofstream test_output; test_output.open(filename_sstr.str().c_str()); /* const NodesNeighborList & my_neighbor_list = dynamic_cast<const NodesNeighborList &>(my_contact->getContactSearch().getContactNeighborStructure(master).getNeighborList()); UInt nb_nodes_neigh = my_neighbor_list.impactor_nodes.getSize(); Vector<UInt> impact_nodes = my_neighbor_list.impactor_nodes; UInt * impact_nodes_val = impact_nodes.values; UInt * master_nodes_offset_val = my_neighbor_list.master_nodes_offset.values; UInt * master_nodes_val = my_neighbor_list.master_nodes.values; /// print impactor nodes test_output << "we have " << nb_nodes_neigh << " impactor nodes:"; for (UInt i = 0; i < nb_nodes_neigh; ++i) { test_output << " " << impact_nodes_val[i]; } test_output << std::endl; for (UInt i = 0; i < nb_nodes_neigh; ++i) { test_output << " Impactor node: " << impact_nodes_val[i] << " has master nodes:"; for(UInt mn = master_nodes_offset_val[i]; mn < master_nodes_offset_val[i+1]; ++mn) { test_output << " " << master_nodes_val[mn]; } test_output << std::endl; } */ my_contact->initSearch(); // does nothing so far /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ for(UInt s = 1; s <= max_steps; ++s) { test_output << std::endl << "passing step " << s << "/" << max_steps << std::endl; /// apply a displacement to the slave body if(s == 2) { Real * coord = my_mesh.getNodes().values; for(UInt n = 0; n < nb_nodes; ++n) { if(coord[n*dim + 0] > 0.5) { displacement[n*dim+0] = -0.02; } } } /// integration my_model.explicitPred(); my_model.initializeUpdateResidualData(); /// compute the penetration list test_output << "Before solveContact" << std::endl; PenetrationList * my_penetration_list = new PenetrationList("penetration_list_1"); const_cast<ContactSearch &>(my_contact->getContactSearch()).findPenetration(master, *my_penetration_list); UInt nb_nodes_pen = my_penetration_list->penetrating_nodes.getSize(); Vector<UInt> pen_nodes = my_penetration_list->penetrating_nodes; UInt * pen_nodes_val = pen_nodes.values; test_output << "we have " << nb_nodes_pen << " penetrating nodes:" << std::endl; for (UInt i = 0; i < nb_nodes_pen; ++i) { test_output << "node " << pen_nodes_val[i] << " with disp:"; for (UInt j=0; j<dim; ++j) test_output << " " << std::setprecision(10) << displacement[pen_nodes_val[i]*dim+j]; test_output << std::endl; } test_output << std::endl; delete my_penetration_list; /// solve contact my_contact->solveContact(); /// compute the penetration list test_output << "After solveContact" << std::endl; PenetrationList * my_penetration_list_2 = new PenetrationList("penetration_list_2"); const_cast<ContactSearch &>(my_contact->getContactSearch()).findPenetration(master, *my_penetration_list_2); UInt nb_nodes_pen_2 = my_penetration_list_2->penetrating_nodes.getSize(); Vector<UInt> pen_nodes_2 = my_penetration_list_2->penetrating_nodes; UInt * pen_nodes_2_val = pen_nodes_2.values; test_output << "we have " << nb_nodes_pen_2 << " penetrating nodes:"; for (UInt i = 0; i < nb_nodes_pen_2; ++i) test_output << " " << pen_nodes_2_val[i]; test_output << std::endl; delete my_penetration_list_2; /// further integration my_model.updateResidual(false); my_contact->avoidAdhesion(); my_model.updateAcceleration(); my_model.explicitCorr(); #ifdef AKANTU_USE_IOHELPER paraviewDump(dumper); #endif //AKANTU_USE_IOHELPER } delete my_contact; finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_friction_coefficient/test_ruina_slowness_2d.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_friction_coefficient/test_ruina_slowness_2d.cc index b70c53cb6..872441326 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_friction_coefficient/test_ruina_slowness_2d.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_friction_coefficient/test_ruina_slowness_2d.cc @@ -1,352 +1,352 @@ /** * @file test_ruina_slowness_2d.cc * @author David Kammer <david.kammer@epfl.ch> * @date Mon Mar 07 15:56:42 2011 * * @brief the slowness law of the simplified dieterich friction coefficient * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "friction_coefficient.hh" #include "simplified_dieterich_fric_coef.hh" #include "ruina_slowness_fric_coef.hh" #include "unique_constant_fric_coef.hh" #include "contact_neighbor_structure.hh" #include "regular_grid_neighbor_structure.hh" #include "contact_search.hh" #include "contact_search_explicit.hh" #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); UInt dim = 2; const ElementType element_type = _triangle_3; #ifdef AKANTU_USE_IOHELPER const UInt paraview_type = TRIANGLE1; #endif //AKANTU_USE_IOHELPER //UInt max_steps = 200000; UInt imposing_steps = 1000; Real max_displacement = -0.01; UInt damping_steps = 100000; UInt damping_interval = 200; Real damping_ratio = 0.99; Real sliding_velocity = 10.; UInt nb_inc_vel_steps = 20000; Real updated_displacement = 0.; UInt additional_steps = 200000; UInt max_steps = imposing_steps + damping_steps + nb_inc_vel_steps + additional_steps; /// load mesh Mesh my_mesh(dim); MeshIOMSH mesh_io; mesh_io.read("sliding_cube_2d.msh", my_mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(my_mesh,1,0); MeshUtils::buildSurfaceID(my_mesh); UInt nb_nodes = my_mesh.getNbNodes(); /// declaration of model SolidMechanicsModel my_model(my_mesh); /// model initialization my_model.initVectors(); // initialize the vectors memset(my_model.getForce().values, 0, dim*nb_nodes*sizeof(Real)); memset(my_model.getVelocity().values, 0, dim*nb_nodes*sizeof(Real)); memset(my_model.getAcceleration().values, 0, dim*nb_nodes*sizeof(Real)); memset(my_model.getDisplacement().values, 0, dim*nb_nodes*sizeof(Real)); memset(my_model.getBoundary().values, false, dim*nb_nodes*sizeof(bool)); my_model.initExplicit(); my_model.initModel(); my_model.readMaterials("material.dat"); my_model.initMaterials(); UInt nb_element = my_model.getFEM().getMesh().getNbElement(element_type); Real time_step = my_model.getStableTimeStep(); my_model.setTimeStep(time_step/10.); //UInt max_steps = static_cast<UInt>(needed_time*10/time_step) + imposing_steps + damping_steps + additional_steps; std::cout << "The number of time steps is found to be: " << max_steps << std::endl; Real * velocity_val = my_model.getVelocity().values; my_model.assembleMassLumped(); Surface impactor = 0; Surface rigid_body_surface = 1; Surface master = 2; // modify surface id UInt nb_surfaces = my_mesh.getNbSurfaces(); my_mesh.setNbSurfaces(++nb_surfaces); ElementType surface_element_type = my_mesh.getFacetElementType(element_type); UInt nb_surface_element = my_model.getFEM().getMesh().getNbElement(surface_element_type); UInt * surface_id_val = my_mesh.getSurfaceID(surface_element_type).values; for(UInt i=0; i < nb_surface_element; ++i) { if (surface_id_val[i] == rigid_body_surface) { Real barycenter[dim]; Real * barycenter_p = &barycenter[0]; my_mesh.getBarycenter(i,surface_element_type,barycenter_p); if(barycenter_p[1] > -1.001) { surface_id_val[i] = master; } } } /// contact declaration Contact * contact = Contact::newContact(my_model, _ct_rigid, _cst_expli, _cnst_regular_grid); ContactRigid * my_contact = dynamic_cast<ContactRigid *>(contact); my_contact->initContact(false); my_contact->addMasterSurface(master); my_contact->addImpactorSurfaceToMasterSurface(impactor, master); /* UniqueConstantFricCoef * fric_coef = new UniqueConstantFricCoef(*my_contact, master); fric_coef->setParam("mu", "0.2"); */ RuinaSlownessFricCoef<true> * fric_coef = new RuinaSlownessFricCoef<true>(*my_contact, master); fric_coef->setParam("mu_zero", "0.2"); fric_coef->setParam("a_factor", "0.002"); fric_coef->setParam("b_factor", "0.08"); fric_coef->setParam("v_normalizer", "0.0001"); fric_coef->setParam("theta_normalizer", "0.002"); fric_coef->setParam("d_zero", "0.00001"); //my_contact->setFrictionCoefficient(fric_coef); my_model.updateCurrentPosition(); // neighbor structure uses current position for init my_contact->initNeighborStructure(master); my_contact->initSearch(); // does nothing so far // boundary conditions Vector<UInt> * top_nodes = new Vector<UInt>(0, 1); Vector<UInt> * push_nodes = new Vector<UInt>(0, 1); Real * coordinates = my_mesh.getNodes().values; Real * displacement = my_model.getDisplacement().values; bool * boundary = my_model.getBoundary().values; UInt * surface_to_nodes_offset = my_contact->getSurfaceToNodesOffset().values; UInt * surface_to_nodes = my_contact->getSurfaceToNodes().values; // normal force boundary conditions for(UInt n = surface_to_nodes_offset[impactor]; n < surface_to_nodes_offset[impactor+1]; ++n) { UInt node = surface_to_nodes[n]; Real x_coord = coordinates[node*dim]; Real y_coord = coordinates[node*dim + 1]; if (y_coord > -0.00001) { boundary[node*dim + 1] = true; top_nodes->push_back(node); } if (x_coord < 0.00001) { boundary[node*dim] = true; push_nodes->push_back(node); } } // ground boundary conditions for(UInt n = surface_to_nodes_offset[rigid_body_surface]; n < surface_to_nodes_offset[rigid_body_surface+1]; ++n) { UInt node = surface_to_nodes[n]; Real y_coord = coordinates[node*dim + 1]; if (y_coord < -1.49) boundary[node*dim] = true; boundary[node*dim + 1] = true; } UInt * top_nodes_val = top_nodes->values; UInt * push_nodes_val = push_nodes->values; my_model.updateResidual(); #ifdef AKANTU_USE_IOHELPER /// initialize the paraview output DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(my_model.getFEM().getMesh().getNodes().values, dim, nb_nodes, "coord_ruina_slowness_2d"); dumper.SetConnectivity((int *)my_model.getFEM().getMesh().getConnectivity(element_type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(my_model.getDisplacement().values, dim, "displacements"); dumper.AddNodeDataField(my_model.getVelocity().values, dim, "velocity"); dumper.AddNodeDataField(my_model.getResidual().values, dim, "force"); dumper.AddNodeDataField(my_model.getForce().values, dim, "applied_force"); dumper.AddElemDataField(my_model.getMaterial(0).getStrain(element_type).values, dim*dim, "strain"); dumper.AddElemDataField(my_model.getMaterial(0).getStress(element_type).values, dim*dim, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix("paraview/ruina_slowness_2d/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER std::ofstream out_info; out_info.open("ruina_slowness_2d.csv"); out_info << "%id,ftop,fcont,zone,stickNode,contNode" << std::endl; std::ofstream energy; energy.open("ruina_slowness_2d_energy.csv"); energy << "%id,kin,pot,tot" << std::endl; Real * current_position = my_model.getCurrentPosition().values; /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ for(UInt s = 1; s <= max_steps; ++s) { if(s % 10 == 0) std::cout << "passing step " << s << "/" << max_steps << std::endl; if(s % 20000 == 0){ my_model.updateCurrentPosition(); my_contact->updateContact(); } // impose normal displacement if(s <= imposing_steps) { Real current_displacement = max_displacement/(static_cast<Real>(imposing_steps))*s; for(UInt n=0; n<top_nodes->getSize(); ++n) { UInt node = top_nodes_val[n]; displacement[node*dim + 1] = current_displacement; } } // damp velocity in order to find equilibrium if(s > imposing_steps && s < imposing_steps+damping_steps && s%damping_interval == 0) { for (UInt i=0; i < nb_nodes; ++i) { for (UInt j=0; j < dim; ++j) velocity_val[i*dim + j] *= damping_ratio; } } // give initial velocity if(s > imposing_steps+damping_steps) { Real t_step = my_model.getTimeStep(); Real additional_disp; if (s > imposing_steps+damping_steps+nb_inc_vel_steps) additional_disp = sliding_velocity * t_step; else additional_disp = (s - (imposing_steps+damping_steps))/nb_inc_vel_steps*sliding_velocity*t_step; updated_displacement += additional_disp; for(UInt n=0; n<push_nodes->getSize(); ++n) { UInt node = push_nodes_val[n]; displacement[node*dim] = updated_displacement; } } my_model.explicitPred(); my_model.initializeUpdateResidualData(); my_contact->solveContact(); my_model.updateResidual(false); my_contact->avoidAdhesion(); my_contact->frictionPredictor(); // find the total force applied at the imposed displacement surface (top) Real * residual = my_model.getResidual().values; Real top_force = 0.; for(UInt n=0; n<top_nodes->getSize(); ++n) { UInt node = top_nodes_val[n]; top_force += residual[node*dim + 1]; } // find index of master surface in impactors_information ContactRigid::SurfaceToImpactInfoMap::const_iterator it_imp; it_imp = my_contact->getImpactorsInformation().find(master); // find the total contact force and contact area ContactRigid::ImpactorInformationPerMaster * imp_info = it_imp->second; UInt * active_imp_nodes_val = imp_info->active_impactor_nodes->values; Real contact_force = 0.; Real contact_zone = 0.; for (UInt i = 0; i < imp_info->active_impactor_nodes->getSize(); ++i) { UInt node = active_imp_nodes_val[i]; contact_force += residual[node*dim + 1]; contact_zone = std::max(contact_zone, current_position[node*dim]); } out_info << s << "," << top_force << "," << contact_force << "," << contact_zone << ","; my_model.updateAcceleration(); const Vector<bool> * sticking_nodes = imp_info->node_is_sticking; bool * sticking_nodes_val = sticking_nodes->values; UInt nb_sticking_nodes = 0; for (UInt i = 0; i < imp_info->active_impactor_nodes->getSize(); ++i) { if(sticking_nodes_val[i*2]) nb_sticking_nodes++; } out_info << nb_sticking_nodes << "," << imp_info->active_impactor_nodes->getSize() << std::endl; my_model.explicitCorr(); my_contact->frictionCorrector(); Real epot = my_model.getPotentialEnergy(); Real ekin = my_model.getKineticEnergy(); energy << s << "," << ekin << "," << epot << "," << ekin+epot << std::endl; #ifdef AKANTU_USE_IOHELPER if(s % 100 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } out_info.close(); energy.close(); delete fric_coef; delete my_contact; finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_contact_2d_neighbor_structure/test_contact_2d_neighbor_structure.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_contact_2d_neighbor_structure/test_contact_2d_neighbor_structure.cc index 290e43bc4..2da72c64a 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_contact_2d_neighbor_structure/test_contact_2d_neighbor_structure.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_contact_2d_neighbor_structure/test_contact_2d_neighbor_structure.cc @@ -1,259 +1,260 @@ /** * @file test_contact_2d_neighbor_structure.cc * @author Leonardo Snozzi <leonardo.snozzi@epfl.ch> * @date Thu Dec 9 10:07:58 2010 * * @brief Test neighbor structure for 2d with linear triangles * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_2d_explicit.hh" #include "contact_neighbor_structure.hh" using namespace akantu; #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; static void initParaview(Mesh & mesh); static void initParaviewSurface(Mesh & mesh); static void printParaviewSurface(Mesh & mesh, const NeighborList & my_neighbor_list); double * facet_id; double * node_id; DumperParaview dumper_surface; #endif //AKANTU_USE_IOHELPER int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); int spatial_dimension = 2; Real time_factor = 0.2; /// load mesh Mesh mesh(spatial_dimension); MeshIOMSH mesh_io; mesh_io.read("squares.msh", mesh); SolidMechanicsModel * model = new SolidMechanicsModel(mesh); UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); UInt nb_elements = model->getFEM().getMesh().getNbElement(_triangle_3); /// model initialization model->initModel(); model->initVectors(); model->readMaterials("materials.dat"); model->initMaterials(); model->initExplicit(); std::cout << model->getMaterial(0) << std::endl; model->assembleMassLumped(); /// set vectors to zero memset(model->getForce().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getVelocity().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getAcceleration().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getDisplacement().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getResidual().values, 0, spatial_dimension*nb_nodes*sizeof(Real)); memset(model->getMaterial(0).getStrain(_triangle_3).values, 0, spatial_dimension*spatial_dimension*nb_elements*sizeof(Real)); memset(model->getMaterial(0).getStress(_triangle_3).values, 0, spatial_dimension*spatial_dimension*nb_elements*sizeof(Real)); /// Paraview Helper #ifdef AKANTU_USE_IOHELPER // initParaview(*model); #endif //AKANTU_USE_IOHELPER // /// dump surface information to paraview // #ifdef AKANTU_USE_IOHELPER // DumperParaview dumper; // dumper.SetMode(TEXT); // dumper.SetPoints(mesh.getNodes().values, spatial_dimension, nb_nodes, "triangle_3_test-surface-extraction"); // dumper.SetConnectivity((int*)mesh.getConnectivity(_triangle_3).values, // TRIANGLE1, mesh.getNbElement(_triangle_3), C_MODE); // dumper.SetPrefix("paraview/"); // dumper.Init(); // dumper.Dump(); // #endif //AKANTU_USE_IOHELPER Real time_step = model->getStableTimeStep() * time_factor; std::cout << "Time Step = " << time_step << "s" << std::endl; model->setTimeStep(time_step); /// contact declaration Contact * contact = Contact::newContact(*model, _ct_2d_expli, _cst_2d_expli, _cnst_2d_grid); Contact2dExplicit * my_contact = dynamic_cast<Contact2dExplicit *>(contact); my_contact->initContact(true); my_contact->setFrictionCoefficient(0.); my_contact->initNeighborStructure(); /// get master surfaces with associated neighbor list // const std::vector<Surface> & master_surfaces = my_contact->getMasterSurfaces(); std::vector<Surface>::iterator it; // for (it = master_surfaces.begin(); it != master_surfaces.end(); ++it) { #ifdef AKANTU_USE_IOHELPER initParaview(mesh); initParaviewSurface(mesh); #endif //AKANTU_USE_IOHELPER UInt nb_surfaces = mesh.getNbSurfaces(); for (UInt s = 0; s < nb_surfaces; ++s) { const NeighborList & my_neighbor_list = my_contact->getContactSearch().getContactNeighborStructure(s).getNeighborList(); #ifdef AKANTU_USE_IOHELPER printParaviewSurface(mesh, my_neighbor_list); #endif //AKANTU_USE_IOHELPER UInt nb_impactors = my_neighbor_list.impactor_nodes.getSize(); UInt * impactors_val = my_neighbor_list.impactor_nodes.values; UInt * node_facet_off_val = my_neighbor_list.facets_offset(_segment_2).storage(); UInt * node_facet_val = my_neighbor_list.facets(_segment_2).storage(); /// print impactor nodes std::cout << "Master surface " << s << " has " << nb_impactors << " impactor nodes:" << std::endl; for (UInt i = 0; i < nb_impactors; ++i) { std::cout << " node " << impactors_val[i] << " : "; for (UInt j = node_facet_off_val[i]; j < node_facet_off_val[i+1]; ++j) std::cout << node_facet_val[j] << " "; std::cout << std::endl; } std::cout << std::endl; } // } #ifdef AKANTU_USE_IOHELPER delete [] node_id; delete [] facet_id; #endif //AKANTU_USE_IOHELPER delete my_contact; delete model; finalize(); return EXIT_SUCCESS; } /// Paraview prints #ifdef AKANTU_USE_IOHELPER static void initParaview(Mesh & mesh) { DumperParaview dumper; dumper.SetMode(TEXT); UInt nb_nodes = mesh.getNbNodes(); dumper.SetPoints(mesh.getNodes().values, 2, nb_nodes, "test-2d-neighbor"); dumper.SetConnectivity((int*)mesh.getConnectivity(_triangle_3).values, TRIANGLE1, mesh.getNbElement(_triangle_3), C_MODE); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } static void initParaviewSurface(Mesh & mesh) { //DumperParaview dumper_surface; dumper_surface.SetMode(TEXT); UInt nb_nodes = mesh.getNbNodes(); dumper_surface.SetPoints(mesh.getNodes().values, 2, nb_nodes, "test-2d-neighbor-surface"); dumper_surface.SetConnectivity((int *)mesh.getConnectivity(_segment_2).values, LINE1, mesh.getNbElement(_segment_2), C_MODE); facet_id = new double [mesh.getConnectivity(_segment_2).getSize()]; memset(facet_id, 0, mesh.getConnectivity(_segment_2).getSize()*sizeof(double)); node_id = new double [nb_nodes]; memset(node_id, 0, nb_nodes*sizeof(double)); dumper_surface.AddElemDataField(facet_id, 1, "master_segments"); dumper_surface.AddNodeDataField(node_id, 1, "slave_nodes"); dumper_surface.SetPrefix("paraview/"); dumper_surface.Init(); dumper_surface.Dump(); // delete [] facet_id; // delete [] node_id; // return dumper_surface; } static void printParaviewSurface(Mesh & mesh, const NeighborList & my_neighbor_list) { UInt nb_impactors = my_neighbor_list.impactor_nodes.getSize(); UInt * impactors_val = my_neighbor_list.impactor_nodes.values; UInt nb_facets = my_neighbor_list.facets(_segment_2).getSize(); UInt * node_facet_val = my_neighbor_list.facets(_segment_2).storage(); // double * node_id = new double [mesh.getNbNodes()]; memset(node_id, 0, mesh.getNbNodes()*sizeof(double)); // double * facet_id = new double [mesh.getConnectivity(_segment_2).getSize()]; memset(facet_id, 0, mesh.getConnectivity(_segment_2).getSize()*sizeof(double)); for (UInt n = 0; n < nb_impactors; ++n) node_id[impactors_val[n]] = 1.; for (UInt el = 0; el < nb_facets; ++el) facet_id[node_facet_val[el]] = 1.; dumper_surface.Dump(); } #endif //AKANTU_USE_IOHELPER diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4.cc index 7cd52f0dd..0663a3efa 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4.cc @@ -1,172 +1,173 @@ /** * @file test_regular_grid_tetrahedron_4.cc * @author David Kammer <david.kammer@epfl.ch> * @date Tue Oct 26 16:58:42 2010 * * @brief test regular grid neighbor structure for 3d case * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "contact_neighbor_structure.hh" #include "regular_grid_neighbor_structure.hh" #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); UInt dim = 3; /// load mesh Mesh my_mesh(dim); MeshIOMSH mesh_io; mesh_io.read("cubes.msh", my_mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(my_mesh,1,0); MeshUtils::buildSurfaceID(my_mesh); unsigned int nb_nodes = my_mesh.getNbNodes(); /// dump facet information to paraview #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(my_mesh.getNodes().values, dim, nb_nodes, "tetrahedron_4_test-surface-extraction"); dumper.SetConnectivity((int*)my_mesh.getConnectivity(_tetrahedron_4).values, TETRA1, my_mesh.getNbElement(_tetrahedron_4), C_MODE); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER /// declaration of model SolidMechanicsModel my_model(my_mesh); /// model initialization my_model.initVectors(); // initialize the vectors memset(my_model.getForce().values, 0, 3*nb_nodes*sizeof(Real)); memset(my_model.getVelocity().values, 0, 3*nb_nodes*sizeof(Real)); memset(my_model.getAcceleration().values, 0, 3*nb_nodes*sizeof(Real)); memset(my_model.getDisplacement().values, 0, 3*nb_nodes*sizeof(Real)); my_model.initModel(); my_model.readMaterials("material.dat"); my_model.initMaterials(); Real time_step = my_model.getStableTimeStep(); my_model.setTimeStep(time_step/10.); my_model.assembleMassLumped(); /// contact declaration Contact * contact = Contact::newContact(my_model, _ct_rigid, _cst_2d_expli, _cnst_regular_grid); ContactRigid * my_contact = dynamic_cast<ContactRigid *>(contact); // how to use contact and contact search types for testing the reg grid with normal nl? my_contact->initContact(false); Surface master = 0; Surface impactor = 1; my_contact->addMasterSurface(master); my_contact->addImpactorSurfaceToMasterSurface(impactor, master); my_model.updateCurrentPosition(); // neighbor structure uses current position for init my_contact->initNeighborStructure(master); const NeighborList & my_neighbor_list = my_contact->getContactSearch().getContactNeighborStructure(master).getNeighborList(); UInt nb_nodes_neigh = my_neighbor_list.impactor_nodes.getSize(); Vector<UInt> impact_nodes = my_neighbor_list.impactor_nodes; UInt * impact_nodes_val = impact_nodes.values; UInt * node_to_elem_offset_val = my_neighbor_list.facets_offset(_triangle_3).storage(); UInt * node_to_elem_val = my_neighbor_list.facets(_triangle_3).storage(); /// define output file for testing std::ofstream test_output; test_output.open("test_regular_grid_tetrahedron_4.out"); /// print impactor nodes test_output << "we have " << nb_nodes_neigh << " impactor nodes:" << std::endl; for (UInt i = 0; i < nb_nodes_neigh; ++i) { test_output << " node " << impact_nodes_val[i] << " : "; for (UInt j = node_to_elem_offset_val[i]; j < node_to_elem_offset_val[i+1]; ++j) test_output << node_to_elem_val[j] << " "; test_output << std::endl; } test_output << std::endl; #ifdef AKANTU_USE_IOHELPER DumperParaview dumper_neighbor; dumper_neighbor.SetMode(TEXT); dumper_neighbor.SetPoints(my_mesh.getNodes().values, dim, nb_nodes, "tetrahedron_4_test-neighbor-elements"); dumper_neighbor.SetConnectivity((int *)my_mesh.getConnectivity(_triangle_3).values, TRIANGLE1, my_mesh.getNbElement(_triangle_3), C_MODE); double * neigh_elem = new double [my_mesh.getNbElement(_triangle_3)]; for (UInt i = 0; i < my_mesh.getNbElement(_triangle_3); ++i) neigh_elem[i] = 0.0; UInt visualize_node = 7; UInt n = impact_nodes_val[visualize_node]; test_output << "plot for node: " << n << std::endl; for (UInt i = node_to_elem_offset_val[visualize_node]; i < node_to_elem_offset_val[visualize_node+1]; ++i) neigh_elem[node_to_elem_val[i]] = 1.; dumper_neighbor.AddElemDataField(neigh_elem, 1, "neighbor id"); dumper_neighbor.SetPrefix("paraview/"); dumper_neighbor.Init(); dumper_neighbor.Dump(); delete [] neigh_elem; #endif //AKANTU_USE_IOHELPER delete my_contact; finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4_nodes.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4_nodes.cc index 70796a1c2..a1253e338 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4_nodes.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4_nodes.cc @@ -1,149 +1,150 @@ /** * @file test_regular_grid_tetrahedron_4_nodes.cc * @author David Kammer <david.kammer@epfl.ch> * @date Tue Oct 26 16:58:42 2010 * * @brief test regular grid neighbor structure for 3d case * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "contact_neighbor_structure.hh" #include "regular_grid_neighbor_structure.hh" #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); int dim = 3; /// load mesh Mesh my_mesh(dim); MeshIOMSH mesh_io; mesh_io.read("cubes.msh", my_mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(my_mesh,1,0); MeshUtils::buildSurfaceID(my_mesh); unsigned int nb_nodes = my_mesh.getNbNodes(); /// dump facet and surface information to paraview #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(my_mesh.getNodes().values, dim, nb_nodes, "tetrahedron_4_nodes_test-surface-extraction"); dumper.SetConnectivity((int*)my_mesh.getConnectivity(_tetrahedron_4).values, TETRA1, my_mesh.getNbElement(_tetrahedron_4), C_MODE); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER /// declaration of model SolidMechanicsModel my_model(my_mesh); /// model initialization my_model.initVectors(); // initialize the vectors memset(my_model.getForce().values, 0, 3*nb_nodes*sizeof(Real)); memset(my_model.getVelocity().values, 0, 3*nb_nodes*sizeof(Real)); memset(my_model.getAcceleration().values, 0, 3*nb_nodes*sizeof(Real)); memset(my_model.getDisplacement().values, 0, 3*nb_nodes*sizeof(Real)); my_model.initModel(); my_model.readMaterials("material.dat"); my_model.initMaterials(); Real time_step = my_model.getStableTimeStep(); my_model.setTimeStep(time_step/10.); my_model.assembleMassLumped(); /// contact declaration Contact * contact = Contact::newContact(my_model, _ct_rigid, _cst_expli, _cnst_regular_grid); ContactRigid * my_contact = dynamic_cast<ContactRigid *>(contact); my_contact->initContact(false); Surface master = 0; Surface impactor = 1; my_contact->addMasterSurface(master); my_contact->addImpactorSurfaceToMasterSurface(impactor, master); my_model.updateCurrentPosition(); // neighbor structure uses current position for init my_contact->initNeighborStructure(master); const NodesNeighborList & my_neighbor_list = dynamic_cast<const NodesNeighborList &>(my_contact->getContactSearch().getContactNeighborStructure(master).getNeighborList()); UInt nb_nodes_neigh = my_neighbor_list.impactor_nodes.getSize(); Vector<UInt> impact_nodes = my_neighbor_list.impactor_nodes; UInt * impact_nodes_val = impact_nodes.values; /// define output file for testing std::ofstream test_output; test_output.open("test_regular_grid_tetrahedron_4_nodes.out"); /// print impactor nodes test_output << "we have " << nb_nodes_neigh << " impactor nodes:"; for (UInt i = 0; i < nb_nodes_neigh; ++i) { test_output << " " << impact_nodes_val[i]; } test_output << std::endl; UInt * master_nodes_offset_val = my_neighbor_list.master_nodes_offset.values; UInt * master_nodes_val = my_neighbor_list.master_nodes.values; for (UInt i = 0; i < nb_nodes_neigh; ++i) { test_output << " Impactor node: " << impact_nodes_val[i] << " has master nodes:"; for(UInt mn = master_nodes_offset_val[i]; mn < master_nodes_offset_val[i+1]; ++mn) { test_output << " " << master_nodes_val[mn]; } test_output << std::endl; } delete my_contact; finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4_nodes_no_neighbors.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4_nodes_no_neighbors.cc index c96a312f4..062f97545 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4_nodes_no_neighbors.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_tetrahedron_4_nodes_no_neighbors.cc @@ -1,149 +1,150 @@ /** * @file test_regular_grid_tetrahedron_4_nodes_no_neighbors.cc * @author David Kammer <david.kammer@epfl.ch> * @date Tue Oct 26 16:58:42 2010 * * @brief test regular grid neighbor structure for 3d case if there are no * neighbors * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "contact_neighbor_structure.hh" #include "regular_grid_neighbor_structure.hh" #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); UInt dim = 3; /// load mesh Mesh my_mesh(dim); MeshIOMSH mesh_io; mesh_io.read("cube.msh", my_mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(my_mesh,1,0); MeshUtils::buildSurfaceID(my_mesh); unsigned int nb_nodes = my_mesh.getNbNodes(); /// dump facet and surface information to paraview #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(my_mesh.getNodes().values, dim, nb_nodes, "tetrahedron_4_nodes_no_neighbors_test-surface-extraction"); dumper.SetConnectivity((int*)my_mesh.getConnectivity(_tetrahedron_4).values, TETRA1, my_mesh.getNbElement(_tetrahedron_4), C_MODE); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER /// declaration of model SolidMechanicsModel my_model(my_mesh); /// model initialization my_model.initVectors(); // initialize the vectors memset(my_model.getForce().values, 0, 3*nb_nodes*sizeof(Real)); memset(my_model.getVelocity().values, 0, 3*nb_nodes*sizeof(Real)); memset(my_model.getAcceleration().values, 0, 3*nb_nodes*sizeof(Real)); memset(my_model.getDisplacement().values, 0, 3*nb_nodes*sizeof(Real)); my_model.initModel(); my_model.readMaterials("material.dat"); my_model.initMaterials(); Real time_step = my_model.getStableTimeStep(); my_model.setTimeStep(time_step/10.); my_model.assembleMassLumped(); /// contact declaration Contact * contact = Contact::newContact(my_model, _ct_rigid, _cst_expli, _cnst_regular_grid); ContactRigid * my_contact = dynamic_cast<ContactRigid *>(contact); my_contact->initContact(false); Surface master = 0; my_contact->addMasterSurface(master); my_model.updateCurrentPosition(); // neighbor structure uses current position for init my_contact->initNeighborStructure(master); const NodesNeighborList & my_neighbor_list = dynamic_cast<const NodesNeighborList &>(my_contact->getContactSearch().getContactNeighborStructure(master).getNeighborList()); UInt nb_nodes_neigh = my_neighbor_list.impactor_nodes.getSize(); Vector<UInt> impact_nodes = my_neighbor_list.impactor_nodes; UInt * impact_nodes_val = impact_nodes.values; /// print impactor nodes std::cout << "we have " << nb_nodes_neigh << " impactor nodes:"; for (UInt i = 0; i < nb_nodes_neigh; ++i) { std::cout << " " << impact_nodes_val[i]; } std::cout << std::endl; UInt * master_nodes_offset_val = my_neighbor_list.master_nodes_offset.values; UInt * master_nodes_val = my_neighbor_list.master_nodes.values; for (UInt i = 0; i < nb_nodes_neigh; ++i) { std::cout << " Impactor node: " << impact_nodes_val[i] << " has master nodes:"; for(UInt mn = master_nodes_offset_val[i]; mn < master_nodes_offset_val[i+1]; ++mn) { std::cout << " " << master_nodes_val[mn]; } std::cout << std::endl; } if(nb_nodes_neigh != 0) { std::cout << "This is not correct. It should be: nb_impactor_nodes = 0" << std::endl; return EXIT_FAILURE; } delete my_contact; finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_triangle_3.cc b/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_triangle_3.cc index caf56f20e..61d058255 100644 --- a/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_triangle_3.cc +++ b/test/test_model/test_solid_mechanics_model/test_contact/test_neighbor_structure/test_regular_grid_neighbor_structure/test_regular_grid_triangle_3.cc @@ -1,169 +1,170 @@ /** * @file test_regular_grid_triangle_3.cc * @author David Kammer <david.kammer@epfl.ch> * @date Tue Oct 26 16:58:42 2010 * * @brief test regular grid neighbor structure for 3d case * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "contact.hh" #include "contact_rigid.hh" #include "contact_neighbor_structure.hh" #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); int dim = 2; /// load mesh Mesh my_mesh(dim); MeshIOMSH mesh_io; mesh_io.read("squares.msh", my_mesh); /// build facet connectivity and surface id MeshUtils::buildFacets(my_mesh,1,0); MeshUtils::buildSurfaceID(my_mesh); unsigned int nb_nodes = my_mesh.getNbNodes(); /// dump surface information to paraview #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(my_mesh.getNodes().values, dim, nb_nodes, "triangle_3_test-surface-extraction"); dumper.SetConnectivity((int*)my_mesh.getConnectivity(_triangle_3).values, TRIANGLE1, my_mesh.getNbElement(_triangle_3), C_MODE); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER /// declaration of model SolidMechanicsModel my_model(my_mesh); /// model initialization my_model.initVectors(); /// initialize the vectors memset(my_model.getForce().values, 0, dim*nb_nodes*sizeof(Real)); memset(my_model.getVelocity().values, 0, dim*nb_nodes*sizeof(Real)); memset(my_model.getAcceleration().values, 0, dim*nb_nodes*sizeof(Real)); memset(my_model.getDisplacement().values, 0, dim*nb_nodes*sizeof(Real)); my_model.initModel(); my_model.readMaterials("material.dat"); my_model.initMaterials(); Real time_step = my_model.getStableTimeStep(); my_model.setTimeStep(time_step/10.); my_model.assembleMassLumped(); /// contact declaration Contact * contact = Contact::newContact(my_model, _ct_rigid, _cst_2d_expli, _cnst_regular_grid); ContactRigid * my_contact = dynamic_cast<ContactRigid *>(contact); my_contact->initContact(false); Surface master = 0; Surface impactor = 1; my_contact->addMasterSurface(master); my_contact->addImpactorSurfaceToMasterSurface(impactor, master); my_model.updateCurrentPosition(); // neighbor structure uses current position for init my_contact->initNeighborStructure(master); const NeighborList & my_neighbor_list = my_contact->getContactSearch().getContactNeighborStructure(master).getNeighborList(); UInt nb_nodes_neigh = my_neighbor_list.impactor_nodes.getSize(); Vector<UInt> impact_nodes = my_neighbor_list.impactor_nodes; UInt * impact_nodes_val = impact_nodes.values; UInt * node_to_elem_offset_val = my_neighbor_list.facets_offset(_segment_2).storage(); UInt * node_to_elem_val = my_neighbor_list.facets(_segment_2).storage(); /// define output file for testing std::ofstream test_output; test_output.open("test_regular_grid_triangle_3.out"); /// print impactor nodes test_output << "we have " << nb_nodes_neigh << " impactor nodes:" << std::endl; for (UInt i = 0; i < nb_nodes_neigh; ++i) { test_output << " node " << impact_nodes_val[i] << " : "; for (UInt j = node_to_elem_offset_val[i]; j < node_to_elem_offset_val[i+1]; ++j) test_output << node_to_elem_val[j] << " "; test_output << std::endl; } test_output << std::endl; #ifdef AKANTU_USE_IOHELPER DumperParaview dumper_neighbor; dumper_neighbor.SetMode(TEXT); dumper_neighbor.SetPoints(my_mesh.getNodes().values, dim, nb_nodes, "triangle_3_test-neighbor-elements"); dumper_neighbor.SetConnectivity((int *)my_mesh.getConnectivity(_segment_2).values, LINE1, my_mesh.getNbElement(_segment_2), C_MODE); double * neigh_elem = new double [my_mesh.getNbElement(_segment_2)]; for (UInt i = 0; i < my_mesh.getNbElement(_segment_2); ++i) neigh_elem[i] = 0.0; UInt visualize_node = 1; UInt n = impact_nodes_val[visualize_node]; test_output << "plot for node: " << n << std::endl; for (UInt i = node_to_elem_offset_val[visualize_node]; i < node_to_elem_offset_val[visualize_node+1]; ++i) neigh_elem[node_to_elem_val[i]] = 1.; dumper_neighbor.AddElemDataField(neigh_elem, 1, "neighbor id"); dumper_neighbor.SetPrefix("paraview/"); dumper_neighbor.Init(); dumper_neighbor.Dump(); delete [] neigh_elem; #endif //AKANTU_USE_IOHELPER delete my_contact; finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_materials/io_helper_tools.cc b/test/test_model/test_solid_mechanics_model/test_materials/io_helper_tools.cc index d7d55e1ea..4b673f843 100644 --- a/test/test_model/test_solid_mechanics_model/test_materials/io_helper_tools.cc +++ b/test/test_model/test_solid_mechanics_model/test_materials/io_helper_tools.cc @@ -1,294 +1,294 @@ /** * @file io_helper_tools.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Sep 30 11:13:01 2011 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "io_helper_tools.hh" #include "aka_common.hh" #include "mesh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "static_communicator.hh" // #include "dof_synchronizer.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; /* ------------------------------------------------------------------------ */ template <ElementType type> -static UInt getIOHelperType() { AKANTU_DEBUG_TO_IMPLEMENT(); return -1; }; - -template <> UInt getIOHelperType<_segment_2>() { return LINE1; } -template <> UInt getIOHelperType<_segment_3>() { return LINE2; } -template <> UInt getIOHelperType<_triangle_3>() { return TRIANGLE1; } -template <> UInt getIOHelperType<_triangle_6>() { return TRIANGLE2; } -template <> UInt getIOHelperType<_quadrangle_4>() { return QUAD1; } -template <> UInt getIOHelperType<_quadrangle_8>() { return QUAD2; } -template <> UInt getIOHelperType<_tetrahedron_4>() { return TETRA1; } -template <> UInt getIOHelperType<_tetrahedron_10>() { return TETRA2; } -template <> UInt getIOHelperType<_hexahedron_8>() { return HEX1; } - -static UInt getIOHelperType(ElementType type) { - UInt ioh_type = -1; +static ElemType getIOHelperType() { AKANTU_DEBUG_TO_IMPLEMENT(); return MAX_ELEM_TYPE; }; + +template <> ElemType getIOHelperType<_segment_2>() { return LINE1; } +template <> ElemType getIOHelperType<_segment_3>() { return LINE2; } +template <> ElemType getIOHelperType<_triangle_3>() { return TRIANGLE1; } +template <> ElemType getIOHelperType<_triangle_6>() { return TRIANGLE2; } +template <> ElemType getIOHelperType<_quadrangle_4>() { return QUAD1; } +template <> ElemType getIOHelperType<_quadrangle_8>() { return QUAD2; } +template <> ElemType getIOHelperType<_tetrahedron_4>() { return TETRA1; } +template <> ElemType getIOHelperType<_tetrahedron_10>() { return TETRA2; } +template <> ElemType getIOHelperType<_hexahedron_8>() { return HEX1; } + +static ElemType getIOHelperType(ElementType type) { + ElemType ioh_type; #define GET_IOHELPER_TYPE(type) \ ioh_type = getIOHelperType<type>(); AKANTU_BOOST_ELEMENT_SWITCH(GET_IOHELPER_TYPE); #undef GET_IOHELPER_TYPE return ioh_type; } /* ------------------------------------------------------------------------ */ void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model, const ElementType & type, const std::string & filename) { const Mesh & mesh = model.getFEM().getMesh(); UInt spatial_dimension = mesh.getSpatialDimension(type); UInt nb_nodes = mesh.getNbNodes(); UInt nb_element = mesh.getNbElement(type); std::stringstream filename_sstr; filename_sstr << filename << "_" << type; UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); UInt nproc = StaticCommunicator::getStaticCommunicator()->getNbProc(); dumper.SetMode(TEXT); dumper.SetParallelContext(whoami, nproc); dumper.SetPoints(mesh.getNodes().values, spatial_dimension, nb_nodes, filename_sstr.str().c_str()); dumper.SetConnectivity((int *)mesh.getConnectivity(type).values, getIOHelperType(type), nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model.getAcceleration().values, spatial_dimension, "acceleration"); dumper.AddNodeDataField(model.getMass().values, spatial_dimension, "mass"); dumper.AddNodeDataField(model.getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model.getForce().values, spatial_dimension, "applied_force"); dumper.AddElemDataField(model.getMaterial(0).getStrain(type).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model.getMaterial(0).getStress(type).values, spatial_dimension*spatial_dimension, "stress"); if(dynamic_cast<const MaterialDamage *>(&model.getMaterial(0))) { const MaterialDamage & mat = dynamic_cast<const MaterialDamage &>(model.getMaterial(0)); Real * dam = mat.getDamage(type).storage(); dumper.AddElemDataField(dam, 1, "damage"); } dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* ------------------------------------------------------------------------ */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ // Vector<Real> checkpoint_displacements(0, spatial_dimension); // Vector<Real> checkpoint_velocity(0, spatial_dimension); // Vector<Real> checkpoint_acceleration(0, spatial_dimension); // Vector<Real> checkpoint_force(0, spatial_dimension); // /* ------------------------------------------------------------------------ */ // void checkpointInit(Dumper & dumper, // const SolidMechanicsModel & model, // const ElementType & type, // const std::string & filename) { // UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); // UInt nproc = StaticCommunicator::getStaticCommunicator()->getNbProc(); // Vector<Real> & displacements = model.getDisplacement(); // Vector<Real> & velocity = model.getVelocity(); // Vector<Real> & acceleration = model.getAcceleration(); // Vector<Real> & force = model.getForce(); // DOFSynchronizer & dof_synchronizer = const_cast<DOFSynchronizer &>(model.getDOFSynchronizer()); // dof_synchronizer.initScatterGatherCommunicationScheme(); // if(whoami == 0){ // const Mesh & mesh = model.getFEM().getMesh(); // UInt nb_nodes = mesh.getNbGlobalNodes(); // checkpoint_displacements.resize(nb_nodes); // checkpoint_velocity .resize(nb_nodes); // checkpoint_acceleration .resize(nb_nodes); // checkpoint_force .resize(nb_nodes); // dof_synchronizer.gather(displacements, 0, &checkpoint_displacements); // dof_synchronizer.gather(velocity , 0, &checkpoint_velocity ); // dof_synchronizer.gather(acceleration , 0, &checkpoint_acceleration ); // dof_synchronizer.gather(force , 0, &checkpoint_force ); // UInt nb_element = mesh.getNbElement(type); // UInt spatial_dimension = mesh.getSpatialDimension(type); // std::stringstream filename_sstr; filename_sstr << filename << "_" << type; // dumper.SetMode(COMPRESSED); // dumper.SetParallelContext(whoami, nproc); // dumper.SetPoints(mesh.getNodes().values, // spatial_dimension, nb_nodes, filename_sstr.str().c_str()); // dumper.SetConnectivity((int *)mesh.getConnectivity(type).values, // getIOHelperType(type), nb_element, C_MODE); // dumper.AddNodeDataField(checkpoint_displacements.storage(), spatial_dimension, "displacements"); // dumper.AddNodeDataField(checkpoint_velocity .storage(), spatial_dimension, "velocity"); // dumper.AddNodeDataField(checkpoint_acceleration .storage(), spatial_dimension, "acceleration"); // dumper.AddNodeDataField(checkpoint_force .storage(), spatial_dimension, "applied_force"); // dumper.SetPrefix("restart/"); // dumper.Init(); // dumper.Dump(); // } else { // dof_synchronizer.gather(displacements, 0); // dof_synchronizer.gather(velocity , 0); // dof_synchronizer.gather(acceleration , 0); // dof_synchronizer.gather(force , 0); // } // } // /* ------------------------------------------------------------------------ */ // void checkpoint(Dumper & dumper, // const SolidMechanicsModel & model) { // UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); // DOFSynchronizer & dof_synchronizer = const_cast<DOFSynchronizer &>(model.getDOFSynchronizer()); // Vector<Real> & displacements = model.getDisplacement(); // Vector<Real> & velocity = model.getVelocity(); // Vector<Real> & acceleration = model.getAcceleration(); // Vector<Real> & force = model.getForce(); // if(whoami == 0){ // dof_synchronizer.gather(displacements, 0, &checkpoint_displacements); // dof_synchronizer.gather(velocity , 0, &checkpoint_velocity ); // dof_synchronizer.gather(acceleration , 0, &checkpoint_acceleration ); // dof_synchronizer.gather(force , 0, &checkpoint_force ); // dumper.Dump(); // } else { // dof_synchronizer.gather(displacements, 0); // dof_synchronizer.gather(velocity , 0); // dof_synchronizer.gather(acceleration , 0); // dof_synchronizer.gather(force , 0); // } // } // /* ------------------------------------------------------------------------ */ // /* ------------------------------------------------------------------------ */ // void restart(const SolidMechanicsModel & model, // const ElementType & type, // const std::string & filename) { // UInt whoami = StaticCommunicator::getStaticCommunicator()->whoAmI(); // UInt nproc = StaticCommunicator::getStaticCommunicator()->getNbProc(); // DOFSynchronizer & dof_synchronizer = const_cast<DOFSynchronizer &>(model.getDOFSynchronizer()); // dof_synchronizer.initScatterGatherCommunicationScheme(); // Vector<Real> & displacements = model.getDisplacement(); // Vector<Real> & velocity = model.getVelocity(); // Vector<Real> & acceleration = model.getAcceleration(); // Vector<Real> & force = model.getForce(); // if(whoami == 0){ // const Mesh & mesh = model.getFEM().getMesh(); // UInt nb_nodes = mesh.getNbGlobalNodes(); // UInt spatial_dimension = mesh.getSpatialDimension(type); // std::stringstream filename_sstr; filename_sstr << filename << "_" << type; // ReaderRestart reader; // reader.SetMode(COMPRESSED); // reader.SetParallelContext(whoami, nproc); // reader.SetPoints(filename_sstr.str().c_str()); // reader.SetConnectivity(getIOHelperType(type)); // reader.AddNodeDataField("displacements"); // reader.AddNodeDataField("velocity"); // reader.AddNodeDataField("acceleration"); // reader.AddNodeDataField("applied_force"); // reader.SetPrefix("restart/"); // reader.Init(); // reader.Read(); // Vector<Real> restart_tmp_vect(nb_nodes, spatial_dimension); // displacements.clear(); // velocity.clear(); // acceleration.clear(); // force.clear(); // Real * tmp = reader.GetNodeDataField("displacements"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(displacements, 0, &restart_tmp_vect); // tmp = reader.GetNodeDataField("velocity"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(velocity , 0, &restart_tmp_vect); // tmp = reader.GetNodeDataField("acceleration"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(acceleration , 0, &restart_tmp_vect); // tmp = reader.GetNodeDataField("applied_force"); // std::copy(tmp, tmp + nb_nodes * spatial_dimension, restart_tmp_vect.storage()); // dof_synchronizer.scatter(force , 0, &restart_tmp_vect); // } else { // displacements.clear(); // velocity.clear(); // acceleration.clear(); // force.clear(); // dof_synchronizer.scatter(displacements, 0); // dof_synchronizer.scatter(velocity , 0); // dof_synchronizer.scatter(acceleration , 0); // dof_synchronizer.scatter(force , 0); // } // } /* ------------------------------------------------------------------------ */ diff --git a/test/test_model/test_solid_mechanics_model/test_materials/io_helper_tools.hh b/test/test_model/test_solid_mechanics_model/test_materials/io_helper_tools.hh index f9098b366..3a18587a7 100644 --- a/test/test_model/test_solid_mechanics_model/test_materials/io_helper_tools.hh +++ b/test/test_model/test_solid_mechanics_model/test_materials/io_helper_tools.hh @@ -1,53 +1,55 @@ /** * @file io_helper_tools.hh * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Sep 30 11:15:18 2011 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "solid_mechanics_model.hh" -#include "io_helper.h" +#include "io_helper.hh" + +using namespace iohelper; extern const akantu::UInt spatial_dimension; /* ------------------------------------------------------------------------ */ void paraviewInit(Dumper & dumper, const akantu::SolidMechanicsModel & model, const akantu::ElementType & type, const std::string & filename); void paraviewDump(Dumper & dumper); // void checkpointInit(Dumper & dumper, // const akantu::SolidMechanicsModel & model, // const akantu::ElementType & type, // const std::string & filename); // void checkpoint(Dumper & dumper, // const akantu::SolidMechanicsModel & model); // void restart(const akantu::SolidMechanicsModel & model, // const akantu::ElementType & type, // const std::string & filename); diff --git a/test/test_model/test_solid_mechanics_model/test_materials/test_local_material.cc b/test/test_model/test_solid_mechanics_model/test_materials/test_local_material.cc index 52eff098b..2873ceddc 100644 --- a/test/test_model/test_solid_mechanics_model/test_materials/test_local_material.cc +++ b/test/test_model/test_solid_mechanics_model/test_materials/test_local_material.cc @@ -1,164 +1,165 @@ /** * @file test_local_material.cc * @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> * @author Marion Chambart <marion.chambart@epfl.ch> * @date Tue Jul 27 14:34:13 2010 * * @brief test of the class SolidMechanicsModel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "fem.hh" #include "local_material_damage.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; akantu::Real eps = 1e-10; static void trac(__attribute__ ((unused)) Real * position, double * stress, __attribute__ ((unused)) Real * normal, __attribute__ ((unused)) UInt surface_id){ memset(stress, 0, sizeof(Real)*4); if (fabs(position[0] - 10) < eps){ stress[0] = 3e6; stress[3] = 3e6; } } int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); UInt max_steps = 2000; Real epot, ekin; Real bar_height = 4.; const UInt spatial_dimension = 2; Mesh mesh(spatial_dimension); MeshIOMSH mesh_io; // mesh_io.read("bar.msh", mesh); mesh_io.read("barre_trou.msh", mesh); SolidMechanicsModel * model = new SolidMechanicsModel(mesh); /// model initialization model->initVectors(); UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); memset(model->getForce().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getVelocity().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getAcceleration().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getDisplacement().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getResidual().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getMass().values, 1, nb_nodes*sizeof(Real)); model->initExplicit(); model->initModel(); model->readCustomMaterial<LocalMaterialDamage>("material.dat","LOCAL_DAMAGE"); model->initMaterials(); Real time_step = model->getStableTimeStep(); model->setTimeStep(time_step/10.); model->assembleMassLumped(); std::cout << *model << std::endl; /// Dirichlet boundary conditions for (akantu::UInt i = 0; i < nb_nodes; ++i) { if(model->getFEM().getMesh().getNodes().values[spatial_dimension*i] <= eps) model->getBoundary().values[spatial_dimension*i] = true; if(model->getFEM().getMesh().getNodes().values[spatial_dimension*i + 1] <= eps || model->getFEM().getMesh().getNodes().values[spatial_dimension*i + 1] >= bar_height - eps ) { model->getBoundary().values[spatial_dimension*i + 1] = true; } } FEM & fem_boundary = model->getFEMBoundary(); fem_boundary.initShapeFunctions(); fem_boundary.computeNormalsOnControlPoints(); model->computeForcesFromFunction(trac, akantu::_bft_stress); #ifdef AKANTU_USE_IOHELPER model->updateResidual(); DumperParaview dumper; dumper.SetMode(BASE64); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, 2, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(_triangle_6).values, TRIANGLE2, model->getFEM().getMesh().getNbElement(_triangle_6), C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, 2, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, 2, "velocity"); dumper.AddNodeDataField(model->getForce().values, 2, "force"); dumper.AddNodeDataField(model->getMass().values, 1, "Mass"); dumper.AddNodeDataField(model->getResidual().values, 2, "residual"); dumper.AddElemDataField(model->getMaterial(0).getStrain(_triangle_6).values, 4, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(_triangle_6).values, 4, "stress"); LocalMaterialDamage * mat = dynamic_cast<LocalMaterialDamage*>(&(model->getMaterial(0))); AKANTU_DEBUG_ASSERT(mat,"material is not having the right type: something is wrong"); Real * dam = mat->getDamage(_triangle_6).values; dumper.AddElemDataField(dam, 1, "damage"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("force", 1); dumper.SetEmbeddedValue("residual", 1); dumper.SetEmbeddedValue("velocity", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER 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; #ifdef AKANTU_USE_IOHELPER if(s % 100 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_materials/test_material_damage_non_local.cc b/test/test_model/test_solid_mechanics_model/test_materials/test_material_damage_non_local.cc index 12e2d272b..b45d2abfa 100644 --- a/test/test_model/test_solid_mechanics_model/test_materials/test_material_damage_non_local.cc +++ b/test/test_model/test_solid_mechanics_model/test_materials/test_material_damage_non_local.cc @@ -1,168 +1,169 @@ /** * @file test_material_damage_non_local.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Sep 8 17:31:42 2011 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "fem.hh" #include "local_material_damage.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; akantu::Real eps = 1e-10; static void trac(__attribute__ ((unused)) Real * position, double * stress, __attribute__ ((unused)) Real * normal, __attribute__ ((unused)) UInt surface_id){ memset(stress, 0, sizeof(Real)*4); if (fabs(position[0] - 10) < eps){ stress[0] = 3e6; stress[3] = 3e6; } } int main(int argc, char *argv[]) { debug::setDebugLevel(dblWarning); - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); UInt max_steps = 40000; Real bar_height = 4.; const UInt spatial_dimension = 2; Mesh mesh(spatial_dimension); MeshIOMSH mesh_io; mesh_io.read("barre_trou.msh", mesh); SolidMechanicsModel model(mesh); /// model initialization model.initVectors(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); model.initExplicit(); model.initModel(); model.readMaterials("material_damage_non_local.dat"); model.initMaterials(); /// set vectors to 0 model.getForce().clear(); model.getVelocity().clear(); model.getAcceleration().clear(); model.getDisplacement().clear(); Real time_step = model.getStableTimeStep(); model.setTimeStep(time_step/10.); model.assembleMassLumped(); std::cout << model << std::endl; /// Dirichlet boundary conditions for (akantu::UInt i = 0; i < nb_nodes; ++i) { if(model.getFEM().getMesh().getNodes().values[spatial_dimension*i] <= eps) model.getBoundary().values[spatial_dimension*i] = true; if(model.getFEM().getMesh().getNodes().values[spatial_dimension*i + 1] <= eps || model.getFEM().getMesh().getNodes().values[spatial_dimension*i + 1] >= bar_height - eps ) { model.getBoundary().values[spatial_dimension*i + 1] = true; } } FEM & fem_boundary = model.getFEMBoundary(); fem_boundary.initShapeFunctions(); fem_boundary.computeNormalsOnControlPoints(); model.computeForcesFromFunction(trac, akantu::_bft_stress); MaterialDamage & mat = dynamic_cast<MaterialDamage &>((model.getMaterial(0))); #ifdef AKANTU_USE_IOHELPER model.updateResidual(); DumperParaview dumper; dumper.SetMode(BASE64); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, 2, nb_nodes, "coordinates_damage_nl"); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(_triangle_6).values, TRIANGLE2, model.getFEM().getMesh().getNbElement(_triangle_6), C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, 2, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, 2, "velocity"); dumper.AddNodeDataField(model.getForce().values, 2, "force"); dumper.AddNodeDataField(model.getMass().values, 1, "Mass"); dumper.AddNodeDataField(model.getResidual().values, 2, "residual"); dumper.AddElemDataField(mat.getStrain(_triangle_6).values, 4, "strain"); dumper.AddElemDataField(mat.getStress(_triangle_6).values, 4, "stress"); Real * dam = mat.getDamage(_triangle_6).values; dumper.AddElemDataField(dam, 1, "damage"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("force", 1); dumper.SetEmbeddedValue("residual", 1); dumper.SetEmbeddedValue("velocity", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER // mat.savePairs("cl_pairs"); for(UInt s = 0; s < max_steps; ++s) { model.explicitPred(); model.updateResidual(); model.updateAcceleration(); model.explicitCorr(); if(s % 100 == 0) std::cout << "Step " << s+1 << "/" << max_steps <<std::endl; #ifdef AKANTU_USE_IOHELPER if(s % 100 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_materials/test_material_elastic_caughey.cc b/test/test_model/test_solid_mechanics_model/test_materials/test_material_elastic_caughey.cc index 80e33bad0..6d96b3348 100644 --- a/test/test_model/test_solid_mechanics_model/test_materials/test_material_elastic_caughey.cc +++ b/test/test_model/test_solid_mechanics_model/test_materials/test_material_elastic_caughey.cc @@ -1,149 +1,149 @@ /** * @file test_material_elastic_caughey.cc * @author David Kammer <david.kammer@epfl.ch> * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Wed May 4 16:22:17 2011 * * @brief test of the material elastic caughey * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER # include "io_helper_tools.hh" #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::debug::setDebugLevel(akantu::dblWarning); const ElementType element_type = TYPE; UInt dim = Mesh::getSpatialDimension(element_type); /// load mesh Mesh mesh(dim); MeshIOMSH mesh_io; std::stringstream meshname_sstr; meshname_sstr << "test_material_elastic_caughey_" << element_type << ".msh"; mesh_io.read(meshname_sstr.str().c_str(), mesh); UInt max_steps = 2000; Real time_factor = 0.8; UInt nb_nodes = mesh.getNbNodes(); SolidMechanicsModel model(mesh); /* ------------------------------------------------------------------------ */ /* Initialization */ /* ------------------------------------------------------------------------ */ model.initVectors(); model.getForce().clear(); model.getVelocity().clear(); model.getAcceleration().clear(); model.getDisplacement().clear(); model.updateResidual(); model.initExplicit(); model.initModel(); model.readMaterials("material_elastic_caughey.dat"); model.initMaterials(); std::cout << model.getMaterial(0) << std::endl; model.assembleMassLumped(); /* ------------------------------------------------------------------------ */ /* Boundary + initial conditions */ /* ------------------------------------------------------------------------ */ Real eps = 1e-16; for (UInt i = 0; i < nb_nodes; ++i) { if(mesh.getNodes().values[dim*i] >= 9) model.getDisplacement().values[dim*i] = (mesh.getNodes().values[dim*i] - 9) / 100.; if(mesh.getNodes().values[dim*i] <= eps) model.getBoundary().values[dim*i] = true; if(mesh.getNodes().values[dim*i + 1] <= eps || mesh.getNodes().values[dim*i + 1] >= 1 - eps ) { model.getBoundary().values[dim*i + 1] = true; } } /// dump facet and surface information to paraview #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper, model, element_type, "test_mat_el_caughey"); #endif //AKANTU_USE_IOHELPER std::stringstream filename_sstr; filename_sstr << "test_material_elastic_caughey_" << element_type << ".out"; std::ofstream energy; energy.open(filename_sstr.str().c_str()); energy << "id epot ekin tot" << std::endl; /// Setting time step Real time_step = model.getStableTimeStep() * time_factor; std::cout << "Time Step = " << time_step << "s" << std::endl; model.setTimeStep(time_step); /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ for(UInt s = 1; s <= max_steps; ++s) { model.explicitPred(); model.updateResidual(); model.updateAcceleration(); model.explicitCorr(); Real epot = model.getPotentialEnergy(); Real ekin = model.getKineticEnergy(); if(s % 10 == 0) { std::cerr << "passing step " << s << "/" << max_steps << std::endl; energy << s << " " << epot << " " << ekin << " " << epot + ekin << std::endl; } #ifdef AKANTU_USE_IOHELPER if(s % 10 == 0) paraviewDump(dumper); #endif //AKANTU_USE_IOHELPER } finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_materials/test_material_elastic_caughey_damping.cc b/test/test_model/test_solid_mechanics_model/test_materials/test_material_elastic_caughey_damping.cc index 411eba92f..ef34771d0 100644 --- a/test/test_model/test_solid_mechanics_model/test_materials/test_material_elastic_caughey_damping.cc +++ b/test/test_model/test_solid_mechanics_model/test_materials/test_material_elastic_caughey_damping.cc @@ -1,197 +1,197 @@ /** * @file test_material_elastic_caughey_damping.cc * @author David Kammer <david.kammer@epfl.ch> * @date Fri May 27 14:36:55 2011 * * @brief test of the material elastic caughey - physical aspecte * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER # include "io_helper_tools.hh" #endif //AKANTU_USE_IOHELPER using namespace akantu; bool testFloat(Real a, Real b, Real adm_error); int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::debug::setDebugLevel(akantu::dblWarning); const ElementType element_type = TYPE; UInt dim = Mesh::getSpatialDimension(element_type); /// load mesh Mesh mesh(dim); MeshIOMSH mesh_io; std::stringstream meshname_sstr; meshname_sstr << "single_" << element_type << ".msh"; mesh_io.read(meshname_sstr.str().c_str(), mesh); UInt max_steps = 1000; Real time_factor = 0.1; UInt nb_nodes = mesh.getNbNodes(); SolidMechanicsModel model(mesh); /* ------------------------------------------------------------------------ */ /* Initialization */ /* ------------------------------------------------------------------------ */ model.initVectors(); model.getForce().clear(); model.getVelocity().clear(); model.getAcceleration().clear(); model.getDisplacement().clear(); model.updateResidual(); model.initExplicit(); model.initModel(); model.readMaterials("material_elastic_caughey_damping.dat"); MaterialElasticCaughey & my_mat = dynamic_cast<MaterialElasticCaughey & >(model.getMaterial(0)); Real a_value = 1e-6;//3.836e-06; my_mat.setAlpha(a_value); model.initMaterials(); std::cout << model.getMaterial(0) << std::endl; model.assembleMassLumped(); /* ------------------------------------------------------------------------ */ /* Boundary + initial conditions */ /* ------------------------------------------------------------------------ */ Vector<UInt> the_nodes(0,1); Real imposed_disp = 0.1; for (UInt i = 0; i < nb_nodes; ++i) { // block lower nodes if(mesh.getNodes().values[i*dim+1] < 0.5) { for (UInt j=0; j<dim; ++j) model.getBoundary().values[dim*i + j] = true; } // impose displacement else { model.getBoundary().values[dim*i + 0] = true; model.getDisplacement().values[dim*i + 1] = imposed_disp; the_nodes.push_back(i); } } model.updateResidual(); #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper, model, element_type, "test_mat_el_cau_dump"); #endif //AKANTU_USE_IOHELPER /// Setting time step Real time_step = model.getStableTimeStep() * time_factor; std::cout << "Time Step = " << time_step << "s" << std::endl; model.setTimeStep(time_step); /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ for(UInt s = 1; s <= max_steps; ++s) { if (s%100 == 0) std::cout << "passing step " << s << "/" << max_steps << std::endl; model.explicitPred(); model.updateResidual(); model.updateAcceleration(); model.explicitCorr(); #ifdef AKANTU_USE_IOHELPER if(s % 100 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } /* for (UInt i=0; i<the_nodes.getSize(); ++i) { std::cout << "disp " << model.getDisplacement().values[the_nodes(i)*dim+1] << "; vel " << model.getVelocity().values[the_nodes(i)*dim+1] << std::endl; } */ /* ------------------------------------------------------------------------ */ /* Test solution */ /* ------------------------------------------------------------------------ */ Real disp_tol = 1e-07; Real velo_tol = 1e-03; // solution triangle_3 Vector<Real> disp_triangle_3(0,1); disp_triangle_3.push_back(-0.0344941); Vector<Real> velo_triangle_3(0,1); velo_triangle_3.push_back(-433.9); // solution quadrangle_4 Vector<Real> disp_quadrangle_4(0,1); disp_quadrangle_4.push_back(0.0338388); disp_quadrangle_4.push_back(0.0338388); Vector<Real> velo_quadrangle_4(0,1); velo_quadrangle_4.push_back(-307.221); velo_quadrangle_4.push_back(-307.221); // pointer to solution Vector<Real> * disp = NULL; Vector<Real> * velo = NULL; if (element_type == _triangle_3) { disp = &disp_triangle_3; velo = &velo_triangle_3; } else if (element_type == _quadrangle_4) { disp = &disp_quadrangle_4; velo = &velo_quadrangle_4; } for (UInt i=0; i<the_nodes.getSize(); ++i) { UInt node = the_nodes.values[i]; if (!testFloat(model.getDisplacement().values[node*dim+1], disp->values[i], disp_tol)) { std::cout << "Node " << node << " has wrong disp. Computed = " << model.getDisplacement().values[node*dim+1] << " Solution = " << disp->values[i] << std::endl; return EXIT_FAILURE; } if (!testFloat(model.getVelocity().values[node*dim+1], velo->values[i], velo_tol)) { std::cout << "Node " << node << " has wrong velo. Computed = " << model.getVelocity().values[node*dim+1] << " Solution = " << velo->values[i] << std::endl; return EXIT_FAILURE; } } finalize(); std::cout << "Patch test successful!" << std::endl; return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ bool testFloat(Real a, Real b, Real adm_error) { if (fabs(a-b) < adm_error) return true; else return false; } diff --git a/test/test_model/test_solid_mechanics_model/test_materials/test_material_non_local.cc b/test/test_model/test_solid_mechanics_model/test_materials/test_material_non_local.cc index 7f069f829..1423053f2 100644 --- a/test/test_model/test_solid_mechanics_model/test_materials/test_material_non_local.cc +++ b/test/test_model/test_solid_mechanics_model/test_materials/test_material_non_local.cc @@ -1,176 +1,178 @@ /** * @file test_non_local_material.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Mon Aug 22 14:07:08 2011 * * @brief test of the main part of the non local materials * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; + void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model); void paraviewDump(Dumper & dumper); #endif ByElementTypeReal quadrature_points_volumes("quadrature_points_volumes", "test"); const ElementType TYPE = _triangle_6; int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); debug::setDebugLevel(akantu::dblWarning); UInt spatial_dimension = 2; Mesh mesh(spatial_dimension); MeshIOMSH mesh_io; mesh_io.read("mesh.msh", mesh); SolidMechanicsModel model(mesh); model.initModel(); model.initVectors(); model.readMaterials("material_non_local.dat"); model.initMaterials(); model.getFEM().getMesh().initByElementTypeVector(quadrature_points_volumes, 1, 0); const MaterialNonLocal & mat = dynamic_cast<const MaterialNonLocal &>(model.getMaterial(0)); mat.computeQuadraturePointsNeighborhoudVolumes(quadrature_points_volumes); Real radius = mat.getRadius(); UInt nb_element = mesh.getNbElement(TYPE); UInt nb_tot_quad = model.getFEM().getNbQuadraturePoints(TYPE) * nb_element; Vector<Real> quads(0, spatial_dimension); quads.resize(nb_tot_quad); model.getFEM().interpolateOnQuadraturePoints(mesh.getNodes(), quads, spatial_dimension, TYPE); Vector<Real>::iterator<types::RVector> first_quad_1 = quads.begin(spatial_dimension); Vector<Real>::iterator<types::RVector> last_quad_1 = quads.end(spatial_dimension); std::ofstream pout; pout.open("bf_pairs"); UInt q1 = 0; for(;first_quad_1 != last_quad_1; ++first_quad_1, ++q1) { Vector<Real>::iterator<types::RVector> first_quad_2 = quads.begin(spatial_dimension); Vector<Real>::iterator<types::RVector> last_quad_2 = quads.end(spatial_dimension); UInt q2 = 0; for(;first_quad_2 != last_quad_1; ++first_quad_2, ++q2) { if((q2 != q1) && (first_quad_2->distance(*first_quad_1) <= radius)) pout << q1 << " " << q2 <<std::endl; } } pout.close(); mat.savePairs("cl_pairs"); ByElementTypeReal constant("constant_value", "test"); mesh.initByElementTypeVector(constant, 1, 0); Mesh::type_iterator it = mesh.firstType(spatial_dimension); Mesh::type_iterator last_type = mesh.lastType(spatial_dimension); for(; it != last_type; ++it) { UInt nb_quadrature_points = model.getFEM().getNbQuadraturePoints(*it); UInt nb_element = mesh.getNbElement(*it); Vector<Real> & constant_vect = constant(*it); constant_vect.resize(nb_element * nb_quadrature_points); std::fill_n(constant_vect.storage(), nb_quadrature_points * nb_element, 1.); } ByElementTypeReal constant_avg("constant_value_avg", "test"); mesh.initByElementTypeVector(constant_avg, 1, 0); mat.weigthedAvergageOnNeighbours(constant, constant_avg, 1); debug::setDebugLevel(akantu::dblTest); std::cout << constant(TYPE) << std::endl; std::cout << constant_avg(TYPE) << std::endl; debug::setDebugLevel(akantu::dblWarning); #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper, model); #endif akantu::finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ /* Dumper vars */ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ -template <ElementType type> UInt paraviewType(); -template <> UInt paraviewType<_segment_2>() { return LINE1; }; -template <> UInt paraviewType<_segment_3>() { return LINE2; }; -template <> UInt paraviewType<_triangle_3>() { return TRIANGLE1; }; -template <> UInt paraviewType<_triangle_6>() { return TRIANGLE2; }; -template <> UInt paraviewType<_quadrangle_4>() { return QUAD1; }; -template <> UInt paraviewType<_tetrahedron_4>() { return TETRA1; }; -template <> UInt paraviewType<_tetrahedron_10>() { return TETRA2; }; -template <> UInt paraviewType<_hexahedron_8>() { return HEX1; }; +template <ElementType type> ElemType paraviewType(); +template <> ElemType paraviewType<_segment_2>() { return LINE1; }; +template <> ElemType paraviewType<_segment_3>() { return LINE2; }; +template <> ElemType paraviewType<_triangle_3>() { return TRIANGLE1; }; +template <> ElemType paraviewType<_triangle_6>() { return TRIANGLE2; }; +template <> ElemType paraviewType<_quadrangle_4>() { return QUAD1; }; +template <> ElemType paraviewType<_tetrahedron_4>() { return TETRA1; }; +template <> ElemType paraviewType<_tetrahedron_10>() { return TETRA2; }; +template <> ElemType paraviewType<_hexahedron_8>() { return HEX1; }; /* -------------------------------------------------------------------------- */ void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model) { UInt spatial_dimension = ElementClass<TYPE>::getSpatialDimension(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); UInt nb_element = model.getFEM().getMesh().getNbElement(TYPE); std::stringstream filename; filename << "material_non_local_" << TYPE; dumper.SetMode(TEXT); dumper.SetParallelContext(StaticCommunicator::getStaticCommunicator()->whoAmI(), StaticCommunicator::getStaticCommunicator()->getNbProc()); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, filename.str().c_str()); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(TYPE).values, paraviewType<TYPE>(), nb_element, C_MODE); dumper.AddElemDataField(quadrature_points_volumes(TYPE).storage(), 1, "volume"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } /* -------------------------------------------------------------------------- */ #endif diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model.cc index b56a64f56..7c4afe6c0 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model.cc @@ -1,211 +1,211 @@ /** * @file test_solid_mechanics_model.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Tue Jul 27 14:34:13 2010 * * @brief test of the class SolidMechanicsModel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "fem.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" #endif //AKANTU_USE_IOHELPER using namespace akantu; void trac(double * position,double * traction){ memset(traction,0,sizeof(Real)*4); traction[0] = 1000; traction[3] = 1000; // if(fabs(position[0])< 1e-4){ // traction[0] = -position[1]; // } } int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); UInt max_steps = 1; Real epot, ekin; Mesh mesh(2); MeshIOMSH mesh_io; mesh_io.read("triangle.msh", mesh); SolidMechanicsModel * model = new SolidMechanicsModel(mesh); /// model initialization model->initVectors(); UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); memset(model->getForce().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getVelocity().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getAcceleration().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getDisplacement().values, 0, 2*nb_nodes*sizeof(Real)); model->readMaterials("material.dat"); model->initMaterials(); model->initModel(); Real time_step = model->getStableTimeStep(); model->setTimeStep(time_step/10.); model->assembleMass(); std::cout << *model << std::endl; /// boundary conditions // Real eps = 1e-16; // for (UInt i = 0; i < nb_nodes; ++i) { // model->getDisplacement().values[2*i] = model->getFEM().getMesh().getNodes().values[2*i] / 100.; // if(model->getFEM().getMesh().getNodes().values[2*i] <= eps) { // model->getBoundary().values[2*i ] = true; // if(model->getFEM().getMesh().getNodes().values[2*i + 1] <= eps) // model->getBoundary().values[2*i + 1] = true; // } // if(model->getFEM().getMesh().getNodes().values[2*i + 1] <= eps) { // model->getBoundary().values[2*i + 1] = true; // } // } FEM & fem_boundary = model->getFEMBoundary(); fem_boundary.initShapeFunctions(); fem_boundary.computeNormalsOnQuadPoints(); model->computeForcesFromFunction(trac,0); // const Mesh::ConnectivityTypeList & type_list = fem_boundary.getMesh().getConnectivityTypeList(); // Mesh::ConnectivityTypeList::const_iterator it; // for(it = type_list.begin(); it != type_list.end(); ++it) { // if(Mesh::getSpatialDimension(*it) != fem_boundary.getElementDimension()) continue; // // ElementType facet_type = Mesh::getFacetElementType(*it); // UInt nb_nodes_per_element = Mesh::getNbNodesPerElement(*it); // UInt nb_quad = FEM::getNbQuadraturePoints(*it); // UInt nb_element; // const Vector<Real> * shapes; // Vector<Real> quad_coords(0,2,"quad_coords"); // const Vector<Real> * normals_on_quad; // nb_element = fem_boundary.getMesh().getNbElement(*it); // fem_boundary.interpolateOnQuadraturePoints(mesh.getNodes(), quad_coords, 2, _segment_2); // normals_on_quad = &(fem_boundary.getNormalsOnQuadPoints(*it)); // shapes = &(fem_boundary.getShapes(*it)); // Vector<Real> * sigma_funct = new Vector<Real>(nb_element, 4*nb_quad, "myfunction"); // Vector<Real> * funct = new Vector<Real>(nb_element, 2*nb_quad, "myfunction"); // Real * sigma_funct_val = sigma_funct->values; // Real * shapes_val = shapes->values; // /// compute t * \phi_i for each nodes of each element // for (UInt el = 0; el < nb_element; ++el) { // for (UInt q = 0; q < nb_quad; ++q) { // trac(quad_coords.values+el*nb_quad*2+q,sigma_funct_val); // sigma_funct_val += 4; // } // } // Math::matrix_vector(2,2,*sigma_funct,*normals_on_quad,*funct); // funct->extendComponentsInterlaced(nb_nodes_per_element,2); // Real * funct_val = funct->values; // for (UInt el = 0; el < nb_element; ++el) { // for (UInt q = 0; q < nb_quad; ++q) { // for (UInt n = 0; n < nb_nodes_per_element; ++n) { // *funct_val++ *= *shapes_val; // *funct_val++ *= *shapes_val++; // } // } // } // Vector<Real> * int_funct = new Vector<Real>(nb_element, 2*nb_nodes_per_element, // "inte_funct"); // fem_boundary.integrate(*funct, *int_funct, 2*nb_nodes_per_element, *it); // delete funct; // fem_boundary.assembleVector(*int_funct,model->getForce(), 2, *it); // delete int_funct; // } // model->getDisplacement().values[1] = 0.1; #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, 2, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(_triangle_3).values, TRIANGLE1, model->getFEM().getMesh().getNbElement(_triangle_3), C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, 2, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, 2, "velocity"); dumper.AddNodeDataField(model->getForce().values, 2, "force"); dumper.AddNodeDataField(model->getResidual().values, 2, "residual"); dumper.AddElemDataField(model->getMaterial(0).getStrain(_triangle_3).values, 4, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(_triangle_3).values, 4, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("force", 1); dumper.SetPrefix("paraview/"); dumper.Init(); #endif //AKANTU_USE_IOHELPER model->setPotentialEnergyFlagOn(); for(UInt s = 0; s < max_steps; ++s) { model->explicitPred(); model->updateResidual(); model->updateAcceleration(); model->explicitCorr(); epot = model->getPotentialEnergy(); ekin = model->getKineticEnergy(); std::cout << s << " " << epot << " " << ekin << " " << epot + ekin << std::endl; #ifdef AKANTU_USE_IOHELPER if(s % 10 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d.cc index 0a521ed49..b6a65eb63 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d.cc @@ -1,294 +1,294 @@ /** * @file test_solid_mechanics_model.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Tue Jul 27 14:34:13 2010 * * @brief test of the class SolidMechanicsModel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; + +ElemType paraview_type = TRIANGLE2; #endif //AKANTU_USE_IOHELPER //#define CHECK_STRESS akantu::ElementType type = akantu::_triangle_6; -#ifdef AKANTU_USE_IOHELPER - akantu::UInt paraview_type = TRIANGLE2; -#endif //AKANTU_USE_IOHELPER akantu::SolidMechanicsModel * model; akantu::UInt spatial_dimension = 2; akantu::UInt nb_nodes; akantu::UInt nb_element; akantu::UInt nb_quadrature_points; akantu::Vector<akantu::Real> * stress; akantu::Vector<akantu::Real> * strain; akantu::Vector<akantu::Real> * damage; #ifdef AKANTU_USE_IOHELPER -static void paraviewInit(Dumper & dumper); -static void paraviewDump(Dumper & dumper); +static void paraviewInit(iohelper::Dumper & dumper); +static void paraviewDump(iohelper::Dumper & dumper); #endif int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); akantu::UInt max_steps = 5000; akantu::Real time_factor = 0.8; // akantu::Real epot, ekin; akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("bar2.msh", mesh); model = new akantu::SolidMechanicsModel(mesh); nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_element = model->getFEM().getMesh().getNbElement(type); /// model initialization model->initVectors(); /// set vectors to 0 model->getForce().clear(); model->getVelocity().clear(); model->getAcceleration().clear(); model->getDisplacement().clear(); model->initExplicit(); model->initModel(); model->readMaterials("material.dat"); std::cout << model->getMaterial(0) << std::endl; model->initMaterials(); model->assembleMassLumped(); nb_quadrature_points = model->getFEM().getNbQuadraturePoints(type); stress = new akantu::Vector<akantu::Real>(nb_element * nb_quadrature_points, spatial_dimension* spatial_dimension); strain = new akantu::Vector<akantu::Real>(nb_element * nb_quadrature_points, spatial_dimension * spatial_dimension); /// boundary conditions akantu::Real eps = 1e-16; const akantu::Vector<akantu::Real> & pos = mesh.getNodes(); akantu::Vector<akantu::Real> & disp = model->getDisplacement(); akantu::Vector<bool> & boun = model->getBoundary(); for (akantu::UInt i = 0; i < nb_nodes; ++i) { if(pos(i, 0) >= 9.) disp(i, 0) = (pos(i, 0) - 9) / 100.; if(pos(i) <= eps) boun(i, 0) = true; if(pos(i, 1) <= eps || pos(i, 1) >= 1 - eps ) boun(i, 1) = true; } /// set the time step akantu::Real time_step = model->getStableTimeStep() * time_factor; std::cout << "Time Step = " << time_step << "s" << std::endl; model->setTimeStep(time_step); #ifdef AKANTU_USE_IOHELPER /// initialize the paraview output model->updateResidual(); - DumperParaview dumper; + iohelper::DumperParaview dumper; paraviewInit(dumper); #endif //AKANTU_USE_IOHELPER #ifdef CHECK_STRESS std::ofstream outfile; outfile.open("stress"); #endif // CHECK_STRESS std::ofstream energy; energy.open("energy_bar_2d.csv"); energy << "id,rtime,epot,ekin,tot" << std::endl; for(akantu::UInt s = 1; s <= max_steps; ++s) { model->explicitPred(); model->updateResidual(); model->updateAcceleration(); model->explicitCorr(); akantu::Real epot = model->getPotentialEnergy(); akantu::Real ekin = model->getKineticEnergy(); energy << s << "," << (s-1)*time_step << "," << epot << "," << ekin << "," << epot + ekin << std::endl; #ifdef CHECK_STRESS /// search the position of the maximum of stress to determine the wave speed akantu::Real max_stress = std::numeric_limits<akantu::Real>::min(); akantu::Real * stress = model->getMaterial(0).getStress(type).values; for (akantu::UInt i = 0; i < nb_element; ++i) { if(max_stress < stress[i*spatial_dimension*spatial_dimension]) { max_stress = stress[i*spatial_dimension*spatial_dimension]; } } akantu::Real * coord = model->getFEM().getMesh().getNodes().values; akantu::Real * disp_val = model->getDisplacement().values; akantu::UInt * conn = model->getFEM().getMesh().getConnectivity(type).values; akantu::UInt nb_nodes_per_element = model->getFEM().getMesh().getNbNodesPerElement(type); akantu::Real * coords = new akantu::Real[spatial_dimension]; akantu::Real min_x = std::numeric_limits<akantu::Real>::max(); akantu::Real max_x = std::numeric_limits<akantu::Real>::min(); akantu::Real stress_range = 5e7; for (akantu::UInt el = 0; el < nb_element; ++el) { if(stress[el*spatial_dimension*spatial_dimension] > max_stress - stress_range) { akantu::UInt el_offset = el * nb_nodes_per_element; memset(coords, 0, spatial_dimension*sizeof(akantu::Real)); for (akantu::UInt n = 0; n < nb_nodes_per_element; ++n) { for (akantu::UInt i = 0; i < spatial_dimension; ++i) { akantu::UInt node = conn[el_offset + n] * spatial_dimension; coords[i] += (coord[node + i] + disp_val[node + i]) / ((akantu::Real) nb_nodes_per_element); } } min_x = min_x < coords[0] ? min_x : coords[0]; max_x = max_x > coords[0] ? max_x : coords[0]; } } outfile << s << " " << .5 * (min_x + max_x) << " " << min_x << " " << max_x << " " << max_x - min_x << " " << max_stress << std::endl; delete [] coords; #endif // CHECK_STRESS #ifdef AKANTU_USE_IOHELPER if(s % 100 == 0) paraviewDump(dumper); #endif //AKANTU_USE_IOHELPER if(s % 100 == 0) std::cout << "passing step " << s << "/" << max_steps << std::endl; } energy.close(); #ifdef CHECK_STRESS outfile.close(); #endif // CHECK_STRESS delete model; akantu::finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ /* Dumper vars */ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -void paraviewInit(Dumper & dumper) { - dumper.SetMode(TEXT); +void paraviewInit(iohelper::Dumper & dumper) { + dumper.SetMode(iohelper::TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "bar2d"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, - paraview_type, nb_element, C_MODE); + paraview_type, nb_element, iohelper::C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model->getAcceleration().values, spatial_dimension, "acceleration"); dumper.AddNodeDataField(model->getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model->getMass().values, 1, "mass"); dumper.AddNodeDataField(model->getForce().values, spatial_dimension, "applied_force"); akantu::Real * mat = new akantu::Real[nb_element * nb_quadrature_points]; akantu::Vector<akantu::UInt> & elem_mat = model->getElementMaterial(type); for (akantu::UInt e = 0; e < nb_element; ++e) { for (akantu::UInt q = 0; q < nb_quadrature_points; ++q) { mat[e * nb_quadrature_points + q] = elem_mat(e, 0); } } akantu::UInt offset = nb_quadrature_points * spatial_dimension * spatial_dimension; akantu::UInt nb_mat = model->getNbMaterials(); for (akantu::UInt m = 0; m < nb_mat; ++m) { akantu::Material & material = model->getMaterial(m); const akantu::Vector<akantu::UInt> & elmat = material.getElementFilter(type); for (akantu::UInt e = 0; e < elmat.getSize(); ++e) { memcpy(stress->values + elmat(e, 0) * offset, material.getStress(type).values + e * offset, offset * sizeof(akantu::Real)); memcpy(strain->values + elmat(e, 0) * offset, material.getStrain(type).values + e * offset, offset * sizeof(akantu::Real)); } } dumper.AddElemDataField(mat, 1, "material"); dumper.AddElemDataField(strain->values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(stress->values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ -void paraviewDump(Dumper & dumper) { +void paraviewDump(iohelper::Dumper & dumper) { akantu::UInt offset = nb_quadrature_points * spatial_dimension * spatial_dimension; akantu::UInt nb_mat = model->getNbMaterials(); for (akantu::UInt m = 0; m < nb_mat; ++m) { akantu::Material & material = model->getMaterial(m); const akantu::Vector<akantu::UInt> & elmat = material.getElementFilter(type); for (akantu::UInt e = 0; e < elmat.getSize(); ++e) { memcpy(stress->values + elmat(e, 0) * offset, material.getStress(type).values + e * offset, offset * sizeof(akantu::Real)); memcpy(strain->values + elmat(e, 0) * offset, material.getStrain(type).values + e * offset, offset * sizeof(akantu::Real)); } } dumper.Dump(); } #endif diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_mass_not_lumped.cc similarity index 53% copy from test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d.cc copy to test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_mass_not_lumped.cc index 0a521ed49..740f528fd 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_mass_not_lumped.cc @@ -1,294 +1,215 @@ /** * @file test_solid_mechanics_model.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Tue Jul 27 14:34:13 2010 * * @brief test of the class SolidMechanicsModel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER +using namespace akantu; + //#define CHECK_STRESS -akantu::ElementType type = akantu::_triangle_6; +akantu::ElementType type = akantu::_triangle_3; #ifdef AKANTU_USE_IOHELPER - akantu::UInt paraview_type = TRIANGLE2; + ElemType paraview_type = TRIANGLE1; #endif //AKANTU_USE_IOHELPER akantu::SolidMechanicsModel * model; akantu::UInt spatial_dimension = 2; akantu::UInt nb_nodes; akantu::UInt nb_element; -akantu::UInt nb_quadrature_points; -akantu::Vector<akantu::Real> * stress; -akantu::Vector<akantu::Real> * strain; -akantu::Vector<akantu::Real> * damage; +akantu::Vector<akantu::Real> * lumped; #ifdef AKANTU_USE_IOHELPER static void paraviewInit(Dumper & dumper); static void paraviewDump(Dumper & dumper); #endif int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); akantu::UInt max_steps = 5000; akantu::Real time_factor = 0.8; // akantu::Real epot, ekin; akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; - mesh_io.read("bar2.msh", mesh); + mesh_io.read("bar1.msh", mesh); model = new akantu::SolidMechanicsModel(mesh); nb_nodes = model->getFEM().getMesh().getNbNodes(); nb_element = model->getFEM().getMesh().getNbElement(type); + lumped = new akantu::Vector<akantu::Real>(nb_nodes, spatial_dimension); + /// model initialization model->initVectors(); /// set vectors to 0 model->getForce().clear(); model->getVelocity().clear(); model->getAcceleration().clear(); model->getDisplacement().clear(); model->initExplicit(); + //model->initImplicit(true); model->initModel(); model->readMaterials("material.dat"); std::cout << model->getMaterial(0) << std::endl; model->initMaterials(); - model->assembleMassLumped(); - nb_quadrature_points = model->getFEM().getNbQuadraturePoints(type); + model->initSolver(); + + model->assembleMass(); + // model->assembleStiffnessMatrix(); - stress = new akantu::Vector<akantu::Real>(nb_element * nb_quadrature_points, - spatial_dimension* spatial_dimension); - strain = new akantu::Vector<akantu::Real>(nb_element * nb_quadrature_points, - spatial_dimension * spatial_dimension); + model->getMassMatrix().lump(*lumped); /// boundary conditions akantu::Real eps = 1e-16; const akantu::Vector<akantu::Real> & pos = mesh.getNodes(); akantu::Vector<akantu::Real> & disp = model->getDisplacement(); akantu::Vector<bool> & boun = model->getBoundary(); for (akantu::UInt i = 0; i < nb_nodes; ++i) { if(pos(i, 0) >= 9.) disp(i, 0) = (pos(i, 0) - 9) / 100.; if(pos(i) <= eps) boun(i, 0) = true; if(pos(i, 1) <= eps || pos(i, 1) >= 1 - eps ) boun(i, 1) = true; } /// set the time step akantu::Real time_step = model->getStableTimeStep() * time_factor; std::cout << "Time Step = " << time_step << "s" << std::endl; model->setTimeStep(time_step); + model->updateResidual(); + model->initialAcceleration(); + #ifdef AKANTU_USE_IOHELPER /// initialize the paraview output - model->updateResidual(); DumperParaview dumper; paraviewInit(dumper); #endif //AKANTU_USE_IOHELPER - -#ifdef CHECK_STRESS - std::ofstream outfile; - outfile.open("stress"); -#endif // CHECK_STRESS - std::ofstream energy; - energy.open("energy_bar_2d.csv"); + energy.open("energy_bar_2d_not_lumped.csv"); energy << "id,rtime,epot,ekin,tot" << std::endl; for(akantu::UInt s = 1; s <= max_steps; ++s) { - model->explicitPred(); + // model->implicitPred(); + // /// convergence loop + // UInt count = 0; + // Real error = 0.; + // do { + // std::cout << "passing step " << s << " " << s * time_step << "s - " << std::setw(4) << count << " : " << std::scientific << error << "\r" << std::flush; + // model->updateResidual(); + // model->solveDynamic(); + // model->implicitCorr(); + // count++; + // } while(!model->testConvergenceIncrement(1e-12, error) && (count < 1000)); + model->explicitPred(); model->updateResidual(); model->updateAcceleration(); model->explicitCorr(); akantu::Real epot = model->getPotentialEnergy(); akantu::Real ekin = model->getKineticEnergy(); energy << s << "," << (s-1)*time_step << "," << epot << "," << ekin << "," << epot + ekin << std::endl; -#ifdef CHECK_STRESS - /// search the position of the maximum of stress to determine the wave speed - akantu::Real max_stress = std::numeric_limits<akantu::Real>::min(); - akantu::Real * stress = model->getMaterial(0).getStress(type).values; - for (akantu::UInt i = 0; i < nb_element; ++i) { - if(max_stress < stress[i*spatial_dimension*spatial_dimension]) { - max_stress = stress[i*spatial_dimension*spatial_dimension]; - } - } - - akantu::Real * coord = model->getFEM().getMesh().getNodes().values; - akantu::Real * disp_val = model->getDisplacement().values; - akantu::UInt * conn = model->getFEM().getMesh().getConnectivity(type).values; - akantu::UInt nb_nodes_per_element = model->getFEM().getMesh().getNbNodesPerElement(type); - akantu::Real * coords = new akantu::Real[spatial_dimension]; - akantu::Real min_x = std::numeric_limits<akantu::Real>::max(); - akantu::Real max_x = std::numeric_limits<akantu::Real>::min(); - - akantu::Real stress_range = 5e7; - for (akantu::UInt el = 0; el < nb_element; ++el) { - if(stress[el*spatial_dimension*spatial_dimension] > max_stress - stress_range) { - akantu::UInt el_offset = el * nb_nodes_per_element; - memset(coords, 0, spatial_dimension*sizeof(akantu::Real)); - for (akantu::UInt n = 0; n < nb_nodes_per_element; ++n) { - for (akantu::UInt i = 0; i < spatial_dimension; ++i) { - akantu::UInt node = conn[el_offset + n] * spatial_dimension; - coords[i] += (coord[node + i] + disp_val[node + i]) - / ((akantu::Real) nb_nodes_per_element); - } - } - min_x = min_x < coords[0] ? min_x : coords[0]; - max_x = max_x > coords[0] ? max_x : coords[0]; - } - } - - - outfile << s << " " << .5 * (min_x + max_x) << " " << min_x << " " << max_x << " " << max_x - min_x << " " << max_stress << std::endl; - - delete [] coords; -#endif // CHECK_STRESS - - #ifdef AKANTU_USE_IOHELPER - if(s % 100 == 0) paraviewDump(dumper); + if(s % 1 == 0) paraviewDump(dumper); #endif //AKANTU_USE_IOHELPER if(s % 100 == 0) std::cout << "passing step " << s << "/" << max_steps << std::endl; } energy.close(); -#ifdef CHECK_STRESS - outfile.close(); -#endif // CHECK_STRESS - delete model; akantu::finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ /* Dumper vars */ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER void paraviewInit(Dumper & dumper) { dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, - spatial_dimension, nb_nodes, "bar2d"); + spatial_dimension, nb_nodes, "bar2d_mass_not_lumped"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model->getAcceleration().values, spatial_dimension, "acceleration"); dumper.AddNodeDataField(model->getResidual().values, spatial_dimension, "force"); - dumper.AddNodeDataField(model->getMass().values, - 1, "mass"); dumper.AddNodeDataField(model->getForce().values, spatial_dimension, "applied_force"); + dumper.AddNodeDataField(lumped->values, + spatial_dimension, "mass"); - akantu::Real * mat = new akantu::Real[nb_element * nb_quadrature_points]; - akantu::Vector<akantu::UInt> & elem_mat = model->getElementMaterial(type); - for (akantu::UInt e = 0; e < nb_element; ++e) { - for (akantu::UInt q = 0; q < nb_quadrature_points; ++q) { - mat[e * nb_quadrature_points + q] = elem_mat(e, 0); - } - } - akantu::UInt offset = nb_quadrature_points * spatial_dimension * spatial_dimension; - akantu::UInt nb_mat = model->getNbMaterials(); - for (akantu::UInt m = 0; m < nb_mat; ++m) { - akantu::Material & material = model->getMaterial(m); - const akantu::Vector<akantu::UInt> & elmat = material.getElementFilter(type); - for (akantu::UInt e = 0; e < elmat.getSize(); ++e) { - memcpy(stress->values + elmat(e, 0) * offset, - material.getStress(type).values + e * offset, - offset * sizeof(akantu::Real)); - memcpy(strain->values + elmat(e, 0) * offset, - material.getStrain(type).values + e * offset, - offset * sizeof(akantu::Real)); - } - } - - dumper.AddElemDataField(mat, 1, "material"); - dumper.AddElemDataField(strain->values, - spatial_dimension*spatial_dimension, "strain"); - dumper.AddElemDataField(stress->values, - spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { - akantu::UInt offset = nb_quadrature_points * spatial_dimension * spatial_dimension; - akantu::UInt nb_mat = model->getNbMaterials(); - for (akantu::UInt m = 0; m < nb_mat; ++m) { - akantu::Material & material = model->getMaterial(m); - const akantu::Vector<akantu::UInt> & elmat = material.getElementFilter(type); - for (akantu::UInt e = 0; e < elmat.getSize(); ++e) { - memcpy(stress->values + elmat(e, 0) * offset, - material.getStress(type).values + e * offset, - offset * sizeof(akantu::Real)); - memcpy(strain->values + elmat(e, 0) * offset, - material.getStrain(type).values + e * offset, - offset * sizeof(akantu::Real)); - } - } - dumper.Dump(); } #endif diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_parallel.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_parallel.cc index d8012809e..3208f940a 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_parallel.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_parallel.cc @@ -1,215 +1,216 @@ /** * @file test_solid_mechanics_model.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Tue Jul 27 14:34:13 2010 * * @brief test of the class SolidMechanicsModel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "static_communicator.hh" #include "distributed_synchronizer.hh" #include "mesh_partition_scotch.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER int main(int argc, char *argv[]) { #ifdef AKANTU_USE_IOHELPER akantu::ElementType type = akantu::_triangle_6; #endif //AKANTU_USE_IOHELPER akantu::UInt spatial_dimension = 2; akantu::UInt max_steps = 5000; akantu::Real time_factor = 0.8; - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::Mesh mesh(spatial_dimension); akantu::StaticCommunicator * comm = akantu::StaticCommunicator::getStaticCommunicator(); akantu::Int psize = comm->getNbProc(); akantu::Int prank = comm->whoAmI(); // std::stringstream filename; // filename << "log-" << prank << ".txt"; // akantu::debug::setLogFile(filename.str()); akantu::debug::setDebugLevel(akantu::dblWarning); akantu::MeshPartition * partition = NULL; if(prank == 0) { akantu::MeshIOMSH mesh_io; mesh_io.read("bar2.msh", mesh); partition = new akantu::MeshPartitionScotch(mesh, spatial_dimension); partition->partitionate(psize); } akantu::SolidMechanicsModel model(mesh); model.initParallel(partition); akantu::UInt nb_nodes = mesh.getNbNodes(); #ifdef AKANTU_USE_IOHELPER akantu::UInt nb_element = mesh.getNbElement(type); #endif //AKANTU_USE_IOHELPER /* ------------------------------------------------------------------------ */ /* Initialization */ /* ------------------------------------------------------------------------ */ /// model initialization model.initVectors(); /// set vectors to 0 model.getForce().clear(); model.getVelocity().clear(); model.getAcceleration().clear(); model.getDisplacement().clear(); model.initExplicit(); model.initModel(); model.readMaterials("material.dat"); model.initMaterials(); if(prank == 0) std::cout << model.getMaterial(0) << std::endl; model.assembleMassLumped(); /* ------------------------------------------------------------------------ */ /* Boundary + initial conditions */ /* ------------------------------------------------------------------------ */ akantu::Real eps = 1e-16; const akantu::Vector<akantu::Real> & pos = mesh.getNodes(); akantu::Vector<akantu::Real> & disp = model.getDisplacement(); akantu::Vector<bool> & boun = model.getBoundary(); for (akantu::UInt i = 0; i < nb_nodes; ++i) { if(pos(i, 0) >= 9.) disp(i, 0) = (pos(i, 0) - 9) / 100.; if(pos(i) <= eps) boun(i, 0) = true; if(pos(i, 1) <= eps || pos(i, 1) >= 1 - eps ) boun(i, 1) = true; } model.synchronizeBoundaries(); #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetParallelContext(prank, psize); dumper.SetPoints(mesh.getNodes().values, spatial_dimension, nb_nodes, "bar2d_para"); dumper.SetConnectivity((int *)mesh.getConnectivity(type).values, TRIANGLE2, nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model.getMass().values, 1, "mass"); dumper.AddNodeDataField(model.getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model.getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model.getAcceleration().values, spatial_dimension, "acceleration"); dumper.AddElemDataField(model.getMaterial(0).getStrain(type).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model.getMaterial(0).getStress(type).values, spatial_dimension*spatial_dimension, "stress"); akantu::UInt nb_quadrature_points = model.getFEM().getNbQuadraturePoints(type); double * part = new double[nb_element*nb_quadrature_points]; for (unsigned int i = 0; i < nb_element; ++i) for (unsigned int q = 0; q < nb_quadrature_points; ++q) part[i*nb_quadrature_points + q] = prank; dumper.AddElemDataField(part, 1, "partitions"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER std::ofstream energy; if(prank == 0) { energy.open("energy_bar_2d_para.csv"); energy << "id,rtime,epot,ekin,tot" << std::endl; } double total_time = 0.; /// Setting time step akantu::Real time_step = model.getStableTimeStep() * time_factor; if(prank == 0) std::cout << "Time Step = " << time_step << "s" << std::endl; model.setTimeStep(time_step); /* ------------------------------------------------------------------------ */ /* Main loop */ /* ------------------------------------------------------------------------ */ for(akantu::UInt s = 1; s <= max_steps; ++s) { double start = MPI_Wtime(); model.explicitPred(); model.updateResidual(); model.updateAcceleration(); model.explicitCorr(); double end = MPI_Wtime(); akantu::Real epot = model.getPotentialEnergy(); akantu::Real ekin = model.getKineticEnergy(); total_time += end - start; if(prank == 0 && (s % 100 == 0)) { std::cerr << "passing step " << s << "/" << max_steps << std::endl; } energy << s << "," << (s-1)*time_step << "," << epot << "," << ekin << "," << epot + ekin << std::endl; #ifdef AKANTU_USE_IOHELPER if(s % 100 == 0) { dumper.Dump(); } #endif //AKANTU_USE_IOHELPER } if(prank == 0) std::cout << "Time : " << psize << " " << total_time / max_steps << " " << total_time << std::endl; #ifdef AKANTU_USE_IOHELPER delete [] part; #endif //AKANTU_USE_IOHELPER akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_structured.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_structured.cc index 7bb0f579c..006db376d 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_structured.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_bar_traction2d_structured.cc @@ -1,126 +1,126 @@ /** * @file test_solid_mechanics_model.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Tue Jul 27 14:34:13 2010 * * @brief test of the class SolidMechanicsModel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" #endif //AKANTU_USE_IOHELPER int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); akantu::UInt spatial_dimension = 2; akantu::UInt max_steps = 10000; akantu::Real time_factor = 0.2; akantu::Real epot, ekin; akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("bar_structured1.msh", mesh); akantu::SolidMechanicsModel * model = new akantu::SolidMechanicsModel(mesh); /// model initialization model->initVectors(); /// set vectors to 0 akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); memset(model->getForce().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getVelocity().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getAcceleration().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getDisplacement().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); model->initExplicit(); model->initModel(); model->readMaterials("material.dat"); model->initMaterials(); std::cout << model->getMaterial(0) << std::endl; model->assembleMassLumped(); /// boundary conditions akantu::Real eps = 1e-16; for (akantu::UInt i = 0; i < nb_nodes; ++i) { if(model->getFEM().getMesh().getNodes().values[spatial_dimension*i] >= 9) model->getDisplacement().values[spatial_dimension*i] = (model->getFEM().getMesh().getNodes().values[spatial_dimension*i] - 9) / 100. ; if(model->getFEM().getMesh().getNodes().values[spatial_dimension*i] <= eps) model->getBoundary().values[spatial_dimension*i] = true; if(model->getFEM().getMesh().getNodes().values[spatial_dimension*i + 1] <= eps || model->getFEM().getMesh().getNodes().values[spatial_dimension*i + 1] >= 1 - eps ) { model->getBoundary().values[spatial_dimension*i + 1] = true; } } akantu::Real time_step = model->getStableTimeStep() * time_factor; std::cout << "Time Step = " << time_step << "s" << std::endl; model->setTimeStep(time_step); std::ofstream energy; energy.open("energy.csv"); energy << "id,epot,ekin,tot" << std::endl; for(akantu::UInt s = 1; s <= max_steps; ++s) { model->explicitPred(); model->updateResidual(); model->updateAcceleration(); model->explicitCorr(); epot = model->getPotentialEnergy(); ekin = model->getKineticEnergy(); std::cerr << "passing step " << s << "/" << max_steps << std::endl; energy << s << "," << epot << "," << ekin << "," << epot + ekin << std::endl; } energy.close(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_circle_2.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_circle_2.cc index 163b649e1..9a7900aa6 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_circle_2.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_circle_2.cc @@ -1,137 +1,138 @@ /** * @file test_solid_mechanics_model.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Tue Jul 27 14:34:13 2010 * * @brief test of the class SolidMechanicsModel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "fem.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" #endif //AKANTU_USE_IOHELPER using namespace akantu; static void trac(__attribute__ ((unused)) Real * position, double * stress, __attribute__ ((unused)) Real * normal, __attribute__ ((unused)) UInt surface_id){ memset(stress,0,sizeof(Real)*4); stress[0] = 1000; stress[3] = 1000; } int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); UInt max_steps = 10000; Real epot, ekin; Mesh mesh(2); MeshIOMSH mesh_io; mesh_io.read("circle2.msh", mesh); SolidMechanicsModel * model = new SolidMechanicsModel(mesh); /// model initialization model->initVectors(); UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); memset(model->getForce().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getVelocity().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getAcceleration().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getDisplacement().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getResidual().values, 0, 2*nb_nodes*sizeof(Real)); memset(model->getMass().values, 1, nb_nodes*sizeof(Real)); model->initExplicit(); model->initModel(); model->readMaterials("material.dat"); model->initMaterials(); Real time_step = model->getStableTimeStep() / 10.; model->setTimeStep(time_step); std::cout << "-- Time step : " << time_step << " --" << std::endl; model->assembleMassLumped(); FEM & fem_boundary = model->getFEMBoundary(); fem_boundary.initShapeFunctions(); fem_boundary.computeNormalsOnControlPoints(); model->computeForcesFromFunction(trac, akantu::_bft_stress); #ifdef AKANTU_USE_IOHELPER - DumperParaview dumper; - dumper.SetMode(BASE64); + iohelper::DumperParaview dumper; + dumper.SetMode(iohelper::BASE64); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, 2, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(_triangle_6).values, - TRIANGLE2, model->getFEM().getMesh().getNbElement(_triangle_6), C_MODE); + iohelper::TRIANGLE2, model->getFEM().getMesh().getNbElement(_triangle_6), + iohelper::C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, 2, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, 2, "velocity"); dumper.AddNodeDataField(model->getForce().values, 2, "force"); dumper.AddNodeDataField(model->getMass().values, 1, "Mass"); dumper.AddNodeDataField(model->getResidual().values, 2, "residual"); dumper.AddElemDataField(model->getMaterial(0).getStrain(_triangle_6).values, 4, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(_triangle_6).values, 4, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("force", 1); dumper.SetEmbeddedValue("residual", 1); dumper.SetEmbeddedValue("velocity", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER for(UInt s = 0; s < max_steps; ++s) { model->explicitPred(); model->updateResidual(); model->updateAcceleration(); model->explicitCorr(); epot = model->getPotentialEnergy(); ekin = model->getKineticEnergy(); std::cout << s << " " << epot << " " << ekin << " " << epot + ekin << std::endl; #ifdef AKANTU_USE_IOHELPER if(s % 100 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_cube3d.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_cube3d.cc index bf2268c81..8bec8bc04 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_cube3d.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_cube3d.cc @@ -1,143 +1,143 @@ /** * @file test_solid_mechanics_model_cube3d.cc * @author Guillaume ANCIAUX <guillaume.anciaux@epfl.ch> * @date Tue Aug 17 11:31:22 2010 * * @brief test of the class SolidMechanicsModel on the 3d cube * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" #endif //AKANTU_USE_IOHELPER int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); akantu::UInt max_steps = 10000; akantu::Real epot, ekin; #ifdef AKANTU_USE_IOHELPER akantu::ElementType type = akantu::_tetrahedron_4; - akantu::UInt paratype = TETRA1; + iohelper::ElemType paratype = iohelper::TETRA1; #endif //AKANTU_USE_IOHELPER akantu::Mesh mesh(3); akantu::MeshIOMSH mesh_io; mesh_io.read("cube1.msh", mesh); akantu::SolidMechanicsModel * model = new akantu::SolidMechanicsModel(mesh); /// model initialization model->initVectors(); /// initialize the vectors akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); memset(model->getForce().values, 0, 3*nb_nodes*sizeof(akantu::Real)); memset(model->getVelocity().values, 0, 3*nb_nodes*sizeof(akantu::Real)); memset(model->getAcceleration().values, 0, 3*nb_nodes*sizeof(akantu::Real)); memset(model->getDisplacement().values, 0, 3*nb_nodes*sizeof(akantu::Real)); model->initExplicit(); model->initModel(); model->readMaterials("material.dat"); model->initMaterials(); akantu::Real time_step = model->getStableTimeStep(); model->setTimeStep(time_step/10.); model->assembleMassLumped(); std::cout << *model << std::endl; /// boundary conditions akantu::Real eps = 1e-16; for (akantu::UInt i = 0; i < nb_nodes; ++i) { model->getDisplacement().values[3*i] = model->getFEM().getMesh().getNodes().values[3*i] / 100.; if(model->getFEM().getMesh().getNodes().values[3*i] <= eps) { model->getBoundary().values[3*i ] = true; } if(model->getFEM().getMesh().getNodes().values[3*i + 1] <= eps) { model->getBoundary().values[3*i + 1] = true; } } // model->getDisplacement().values[1] = 0.1; #ifdef AKANTU_USE_IOHELPER - DumperParaview dumper; + iohelper::DumperParaview dumper; // dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, 3, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, - paratype, model->getFEM().getMesh().getNbElement(type), C_MODE); + paratype, model->getFEM().getMesh().getNbElement(type), iohelper::C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, 3, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, 3, "velocity"); dumper.AddNodeDataField(model->getMass().values, 1, "mass"); dumper.AddNodeDataField(model->getResidual().values, 3, "force"); dumper.AddElemDataField(model->getMaterial(0).getStrain(type).values, 9, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(type).values, 9, "stress"); dumper.SetPrefix("paraview/"); dumper.Init(); #endif //AKANTU_USE_IOHELPER std::ofstream energy; energy.open("energy.csv"); energy << "id,epot,ekin,tot" << std::endl; for(akantu::UInt s = 0; s < max_steps; ++s) { model->explicitPred(); model->updateResidual(); model->updateAcceleration(); model->explicitCorr(); epot = model->getPotentialEnergy(); ekin = model->getKineticEnergy(); std::cerr << "passing step " << s << "/" << max_steps << std::endl; energy << s << "," << epot << "," << ekin << "," << epot + ekin << std::endl; #ifdef AKANTU_USE_IOHELPER if(s % 10 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } energy.close(); akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_cube3d_tetra10.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_cube3d_tetra10.cc index 4d21874dd..b7430ee39 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_cube3d_tetra10.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_cube3d_tetra10.cc @@ -1,141 +1,141 @@ /** * @file test_solid_mechanics_model_cube3d.cc * @author Guillaume ANCIAUX <guillaume.anciaux@epfl.ch> * @date Tue Aug 17 11:31:22 2010 * * @brief test of the class SolidMechanicsModel on the 3d cube * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" #endif //AKANTU_USE_IOHELPER int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); akantu::UInt max_steps = 1000; akantu::Real epot, ekin; #ifdef AKANTU_USE_IOHELPER akantu::ElementType type = akantu::_tetrahedron_10; - akantu::UInt paratype = TETRA2; + iohelper::ElemType paratype = iohelper::TETRA2; #endif //AKANTU_USE_IOHELPER akantu::Mesh mesh(3); akantu::MeshIOMSH mesh_io; mesh_io.read("cube2.msh", mesh); akantu::SolidMechanicsModel * model = new akantu::SolidMechanicsModel(mesh); /// model initialization model->initVectors(); /// initialize the vectors akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); memset(model->getForce().values, 0, 3*nb_nodes*sizeof(akantu::Real)); memset(model->getVelocity().values, 0, 3*nb_nodes*sizeof(akantu::Real)); memset(model->getAcceleration().values, 0, 3*nb_nodes*sizeof(akantu::Real)); memset(model->getDisplacement().values, 0, 3*nb_nodes*sizeof(akantu::Real)); model->initExplicit(); model->initModel(); model->readMaterials("material.dat"); model->initMaterials(); akantu::Real time_step = model->getStableTimeStep(); model->setTimeStep(time_step/10.); model->assembleMassLumped(); std::cout << *model << std::endl; /// boundary conditions akantu::Real eps = 1e-2; for (akantu::UInt i = 0; i < nb_nodes; ++i) { model->getDisplacement().values[3*i] = model->getFEM().getMesh().getNodes().values[3*i] / 100.; if(model->getFEM().getMesh().getNodes().values[3*i] <= eps) { model->getBoundary().values[3*i ] = true; } if(model->getFEM().getMesh().getNodes().values[3*i + 1] <= eps) { model->getBoundary().values[3*i + 1] = true; } } // model->getDisplacement().values[1] = 0.1; #ifdef AKANTU_USE_IOHELPER - DumperParaview dumper; + iohelper::DumperParaview dumper; // dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, 3, nb_nodes, "coordinates2"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, - paratype, model->getFEM().getMesh().getNbElement(type), C_MODE); + paratype, model->getFEM().getMesh().getNbElement(type), iohelper::C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, 3, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, 3, "velocity"); dumper.AddNodeDataField(model->getMass().values, 1, "mass"); dumper.AddNodeDataField(model->getResidual().values, 3, "force"); dumper.AddElemDataField(model->getMaterial(0).getStrain(type).values, 9, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(type).values, 9, "stress"); dumper.SetPrefix("paraview/"); dumper.Init(); #endif //AKANTU_USE_IOHELPER std::ofstream energy; energy.open("energy.csv"); energy << "id,epot,ekin,tot" << std::endl; for(akantu::UInt s = 0; s < max_steps; ++s) { model->explicitPred(); model->updateResidual(); model->updateAcceleration(); model->explicitCorr(); epot = model->getPotentialEnergy(); ekin = model->getKineticEnergy(); std::cerr << "passing step " << s << "/" << max_steps << std::endl; energy << s << "," << epot << "," << ekin << "," << epot + ekin << std::endl; #ifdef AKANTU_USE_IOHELPER if(s % 10 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } energy.close(); akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_1d.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_1d.cc index 49861735e..9bc2a8c14 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_1d.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_1d.cc @@ -1,183 +1,184 @@ /** * @file test_solid_mechanics_model_implicit_1d.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Mon Feb 21 14:56:16 2011 * * @brief test of traction in implicit * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER #ifdef AKANTU_USE_SCOTCH #include "mesh_partition_scotch.hh" #endif int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); #ifdef AKANTU_USE_IOHELPER akantu::ElementType type = akantu::_segment_2; - akantu::UInt paraview_type = LINE1; + ElemType paraview_type = LINE1; #endif //AKANTU_USE_IOHELPER akantu::UInt spatial_dimension = 1; // akantu::UInt max_steps = 10000; // akantu::Real time_factor = 0.2; // akantu::Real epot, ekin; akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("segment1.msh", mesh); // #ifdef AKANTU_USE_SCOTCH // mesh_io.write("bar1_breorder.msh", mesh); // akantu::MeshPartition * partition = new akantu::MeshPartitionScotch(mesh, spatial_dimension); // partition->reorder(); // delete partition; // mesh_io.write("bar1_reorder.msh", mesh); // #endif akantu::SolidMechanicsModel * model = new akantu::SolidMechanicsModel(mesh); akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); #ifdef AKANTU_USE_IOHELPER akantu::UInt nb_element = model->getFEM().getMesh().getNbElement(type); #endif //AKANTU_USE_IOHELPER /// model initialization model->initVectors(); /// set vectors to 0 memset(model->getForce().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getVelocity().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getAcceleration().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getDisplacement().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); model->initModel(); model->readMaterials("material.dat"); model->initMaterials(); model->initImplicit(); std::cout << model->getMaterial(0) << std::endl; /// boundary conditions // akantu::Real eps = 1e-16; // for (akantu::UInt i = 0; i < nb_nodes; ++i) { // if(model->getFEM().getMesh().getNodes().values[spatial_dimension*i] >= (bar_length - bar_length / 10.)) // model->getDisplacement().values[spatial_dimension*i] = (model->getFEM().getMesh().getNodes().values[spatial_dimension*i] - (bar_length - bar_length / 10.)) / 100.; // if(model->getFEM().getMesh().getNodes().values[spatial_dimension*i] <= eps) // model->getBoundary().values[spatial_dimension*i] = true; // if(model->getFEM().getMesh().getNodes().values[spatial_dimension*i + 1] <= eps || // model->getFEM().getMesh().getNodes().values[spatial_dimension*i + 1] >= 1 - eps ) { // model->getBoundary().values[spatial_dimension*i + 1] = true; // } // } // model->getForce().at(0) = -1000; model->getBoundary().at(0,0) = true; model->getForce().at(1,0) = 1000; model->initializeUpdateResidualData(); #ifdef AKANTU_USE_IOHELPER /// initialize the paraview output DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "implicit"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model->getForce().values, spatial_dimension, "applied_force"); dumper.AddNodeDataField(model->getResidual().values, spatial_dimension, "forces"); dumper.AddElemDataField(model->getMaterial(0).getStrain(type).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(type).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetEmbeddedValue("forces", 1); dumper.SetPrefix("paraview/"); dumper.Init(); // dumper.Dump(); #endif //AKANTU_USE_IOHELPER akantu::debug::setDebugLevel(akantu::dblInfo); akantu::UInt count = 0; model->updateResidual(); #ifdef AKANTU_USE_IOHELPER dumper.Dump(); #endif //AKANTU_USE_IOHELPER while(!model->testConvergenceResidual(1e-1) && (count <= 10)) { std::cout << "Iter : " << ++count << std::endl; model->assembleStiffnessMatrix(); model->solveStatic(); model->getStiffnessMatrix().saveMatrix("Ktmp.mtx"); model->updateResidual(); // model->assembleStiffnessMatrix(); #ifdef AKANTU_USE_IOHELPER dumper.Dump(); #endif //AKANTU_USE_IOHELPER } delete model; akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_2d.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_2d.cc index d1d2149c3..9143bf451 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_2d.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_2d.cc @@ -1,189 +1,190 @@ /** * @file test_solid_mechanics_model_implicit_2d.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Mon Feb 14 14:56:16 2011 * * @brief test of traction in implicit * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "static_communicator.hh" #include "distributed_synchronizer.hh" #include "mesh_partition_scotch.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER #ifdef AKANTU_USE_SCOTCH #include "mesh_partition_scotch.hh" #endif #define bar_length 1 #define bar_height 1 // static void traction(__attribute__ ((unused)) double * position,double * stress){ // memset(stress,0,sizeof(akantu::Real)*4); // if((fabs(position[1] - bar_height) < akantu::Math::tolerance) || (fabs(position[0] - bar_length) < akantu::Math::tolerance)) { // stress[0] = 1000; // stress[3] = 1000; // } // } /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { akantu::debug::setDebugLevel(akantu::dblWarning); - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::UInt spatial_dimension = 2; akantu::Mesh mesh(spatial_dimension); akantu::StaticCommunicator * comm = akantu::StaticCommunicator::getStaticCommunicator(); akantu::Int psize = comm->getNbProc(); akantu::Int prank = comm->whoAmI(); akantu::MeshPartition * partition = NULL; if(prank == 0) { akantu::MeshIOMSH mesh_io; mesh_io.read("square_implicit2.msh", mesh); partition = new akantu::MeshPartitionScotch(mesh, spatial_dimension); // partition->reorder(); partition->partitionate(psize); } akantu::SolidMechanicsModel * model = new akantu::SolidMechanicsModel(mesh); model->initParallel(partition); delete partition; akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); /// model initialization model->initVectors(); /// set vectors to 0 memset(model->getForce().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getVelocity().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getAcceleration().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model->getDisplacement().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); model->initModel(); model->readMaterials("material.dat"); model->initMaterials(); model->initImplicit(); if (prank == 0) std::cout << model->getMaterial(0) << std::endl; /// boundary conditions const akantu::Vector<akantu::Real> & position = mesh.getNodes(); akantu::Vector<bool> & boundary = model->getBoundary(); akantu::Vector<akantu::Real> & displacment = model->getDisplacement(); for (akantu::UInt n = 0; n < nb_nodes; ++n) { if(position(n,0) < akantu::Math::getTolerance()) boundary(n,0) = true; if(position(n,1) < akantu::Math::getTolerance()) boundary(n,1) = true; if(std::abs(position(n,0) - bar_length) < akantu::Math::getTolerance()) { boundary(n,0) = true; displacment(n,0) = 0.1; } } #ifdef AKANTU_USE_IOHELPER akantu::ElementType type = akantu::_triangle_6; - akantu::UInt paraview_type = TRIANGLE2; + ElemType paraview_type = TRIANGLE2; akantu::UInt nb_element = model->getFEM().getMesh().getNbElement(type); /// initialize the paraview output DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetParallelContext(prank, psize); dumper.SetPoints(model->getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "implicit"); dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(type).values, paraview_type, nb_element, C_MODE); dumper.AddNodeDataField(model->getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model->getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model->getForce().values, spatial_dimension, "applied_force"); dumper.AddNodeDataField(model->getResidual().values, spatial_dimension, "forces"); dumper.AddElemDataField(model->getMaterial(0).getStrain(type).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model->getMaterial(0).getStress(type).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetEmbeddedValue("forces", 1); dumper.SetPrefix("paraview/"); dumper.Init(); #endif //AKANTU_USE_IOHELPER akantu::UInt count = 0; model->updateResidual(); #ifdef AKANTU_USE_IOHELPER dumper.Dump(); #endif //AKANTU_USE_IOHELPER akantu::Real norm; model->assembleStiffnessMatrix(); while(!model->testConvergenceResidual(1e-3, norm) && (count < 100)) { if (prank == 0) std::cout << "Iter : " << ++count << " - residual norm : " << norm << std::endl; model->solveStatic(); model->updateResidual(); }; #ifdef AKANTU_USE_IOHELPER dumper.Dump(); #endif //AKANTU_USE_IOHELPER delete model; akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_dynamic_2d.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_dynamic_2d.cc index 2a894b446..755093684 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_dynamic_2d.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_implicit_dynamic_2d.cc @@ -1,314 +1,315 @@ /** * @file test_solid_mechanics_model_implicit_dynamic_2d.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Apr 29 11:32:25 2011 * * @brief test of the dynamic implicit code * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "static_communicator.hh" #include "distributed_synchronizer.hh" #include "mesh_partition_scotch.hh" #ifdef AKANTU_USE_SCOTCH #include "mesh_partition_scotch.hh" #endif using namespace akantu; /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model); void paraviewDump(Dumper & dumper); #endif /* -------------------------------------------------------------------------- */ const Real F = 0.5e4; #define bar_length 10. #define bar_height 1. #define bar_depth 1. const ElementType TYPE = _triangle_3; UInt spatial_dimension = 2; Real time_step = 1e-4; Real analytical_solution(Real time) { return 1./pow(M_PI, 4) * ((1. - cos(M_PI*M_PI*time)) + (1. - cos(3*3*M_PI*M_PI*time))/81. + (1. - cos(5*5*M_PI*M_PI*time))/625.); } /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { debug::setDebugLevel(dblWarning); - initialize(&argc, &argv); + initialize(argc, argv); Mesh mesh(spatial_dimension); StaticCommunicator * comm = StaticCommunicator::getStaticCommunicator(); Int psize = comm->getNbProc(); Int prank = comm->whoAmI(); MeshPartition * partition = NULL; if(prank == 0) { MeshIOMSH mesh_io; mesh_io.read("beam_2d_lin.msh", mesh); partition = new MeshPartitionScotch(mesh, spatial_dimension); partition->reorder(); partition->partitionate(psize); } SolidMechanicsModel * model = new SolidMechanicsModel(mesh); model->initParallel(partition); // UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); /// model initialization model->initVectors(); model->initModel(); model->readMaterials("material_implicit_dynamic.dat"); model->initMaterials(); model->initImplicit(true); // boundary conditions const Vector<Real> & position = mesh.getNodes(); Vector<bool> & boundary = model->getBoundary(); Vector<Real> & force = model->getForce(); Vector<Real> & displacment = model->getDisplacement(); //initial conditions model->getForce().clear(); model->getDisplacement().clear(); model->getVelocity().clear(); model->getAcceleration().clear(); // MeshUtils::buildFacets(mesh); // MeshUtils::buildSurfaceID(mesh); // CSR<UInt> surface_nodes; // MeshUtils::buildNodesPerSurface(mesh, surface_nodes); UInt node_to_print = -1; bool print_node = false; // for (UInt s = 0; s < surface_nodes.getNbRows(); ++s) { // CSR<UInt>::iterator snode = surface_nodes.begin(s); // for(; snode != surface_nodes.end(s); ++snode) { // UInt n = *snode; Vector<UInt> node_to_displace; for (UInt n = 0; n < mesh.getNbNodes(); ++n) { Real x = position(n, 0); Real y = position(n, 1); Real z = 0; if(spatial_dimension == 3) z = position(n, 2); if(Math::are_float_equal(x, 0.) && Math::are_float_equal(y, bar_height / 2.)) { boundary(n,0) = true; boundary(n,1) = true; if(spatial_dimension == 3 && Math::are_float_equal(z, bar_depth / 2.)) boundary(n,2) = true; } if(Math::are_float_equal(x, bar_length) && Math::are_float_equal(y, bar_height / 2.)) { boundary(n,1) = true; if(spatial_dimension == 3 && Math::are_float_equal(z, bar_depth / 2.)) boundary(n,2) = true; } if(Math::are_float_equal(x, bar_length / 2.) && Math::are_float_equal(y, bar_height / 2.)) { if(spatial_dimension < 3 || (spatial_dimension == 3 && Math::are_float_equal(z, bar_depth / 2.))) { force(n,1) = F; if(mesh.isLocalOrMasterNode(n)) { print_node = true; node_to_print = n; std::cout << "I, proc " << prank +1 << " handle the print of node " << n << "(" << x << ", "<< y << ", " << z << ")" << std::endl; } } } } // } model->setTimeStep(time_step); model->updateResidual(); std::stringstream out; out << "position-" << TYPE << "_" << std::scientific << time_step << ".csv"; #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper, *model); #endif std::ofstream pos; if(print_node) { pos.open(out.str().c_str()); if(!pos.good()) { std::cerr << "Cannot open file " << out.str() <<std::endl; exit(EXIT_FAILURE); } pos << "id,time,position,solution" << std::endl; } Real time = 0; UInt count = 0; // UInt print_freq = 1; Real error; model->assembleStiffnessMatrix(); model->assembleMass(); // model->assembleMassLumped(); // Vector<Real> lumped_mass(0,spatial_dimension); // model->getMassMatrix().lump(lumped_mass); // debug::setDebugLevel(dblTest); // std::cout << model->getMass() << lumped_mass; // debug::setDebugLevel(dblWarning); model->getMassMatrix().saveMatrix("M.mtx"); model->getStiffnessMatrix().saveMatrix("K.mtx"); /// time loop for (UInt s = 1; time < 0.62; ++s) { model->implicitPred(); /// convergence loop do { if(count > 0 && prank == 0) std::cout << "passing step " << s << " " << s * time_step << "s - " << std::setw(4) << count << " : " << std::scientific << error << "\r" << std::flush; model->updateResidual(); model->solveDynamic(); model->implicitCorr(); count++; } while(!model->testConvergenceIncrement(1e-12, error) && (count < 1000)); if(prank == 0) std::cout << "passing step " << s << " " << s * time_step << "s - " << std::setw(4) << count << " : " << std::scientific << error << std::endl; count = 0; // if(s % print_freq == 0) { // std::cout << "passing step " << s << "/" << max_steps << " " << s * time_step << "s - " << count / print_freq << std::endl; // count = 0; // } if(print_node) pos << s << "," << s * time_step << "," << displacment(node_to_print, 1) << "," << analytical_solution(s*time_step) << std::endl; #ifdef AKANTU_USE_IOHELPER if(s % 10 == 0) paraviewDump(dumper); #endif time += time_step; } if(print_node) pos.close(); delete model; finalize(); return EXIT_SUCCESS; } /* -------------------------------------------------------------------------- */ /* Dumper vars */ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ -template <ElementType type> UInt paraviewType(); -template <> UInt paraviewType<_segment_2>() { return LINE1; }; -template <> UInt paraviewType<_segment_3>() { return LINE2; }; -template <> UInt paraviewType<_triangle_3>() { return TRIANGLE1; }; -template <> UInt paraviewType<_triangle_6>() { return TRIANGLE2; }; -template <> UInt paraviewType<_quadrangle_4>() { return QUAD1; }; -template <> UInt paraviewType<_tetrahedron_4>() { return TETRA1; }; -template <> UInt paraviewType<_tetrahedron_10>() { return TETRA2; }; -template <> UInt paraviewType<_hexahedron_8>() { return HEX1; }; +template <ElementType type> ElemType paraviewType(); +template <> ElemType paraviewType<_segment_2>() { return LINE1; }; +template <> ElemType paraviewType<_segment_3>() { return LINE2; }; +template <> ElemType paraviewType<_triangle_3>() { return TRIANGLE1; }; +template <> ElemType paraviewType<_triangle_6>() { return TRIANGLE2; }; +template <> ElemType paraviewType<_quadrangle_4>() { return QUAD1; }; +template <> ElemType paraviewType<_tetrahedron_4>() { return TETRA1; }; +template <> ElemType paraviewType<_tetrahedron_10>() { return TETRA2; }; +template <> ElemType paraviewType<_hexahedron_8>() { return HEX1; }; /* -------------------------------------------------------------------------- */ void paraviewInit(Dumper & dumper, const SolidMechanicsModel & model) { UInt spatial_dimension = ElementClass<TYPE>::getSpatialDimension(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); UInt nb_element = model.getFEM().getMesh().getNbElement(TYPE); std::stringstream filename; filename << "dynamic_implicit_beam_" << TYPE; dumper.SetMode(TEXT); dumper.SetParallelContext(StaticCommunicator::getStaticCommunicator()->whoAmI(), StaticCommunicator::getStaticCommunicator()->getNbProc()); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, filename.str().c_str()); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(TYPE).values, paraviewType<TYPE>(), nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model.getAcceleration().values, spatial_dimension, "acceleration"); dumper.AddNodeDataField(model.getResidual().values, spatial_dimension, "residual"); dumper.AddNodeDataField(model.getForce().values, spatial_dimension, "applied_force"); dumper.AddElemDataField(model.getMaterial(0).getStrain(TYPE).values, spatial_dimension*spatial_dimension, "strain"); dumper.AddElemDataField(model.getMaterial(0).getStrain(TYPE).values, spatial_dimension*spatial_dimension, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("applied_force", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } /* -------------------------------------------------------------------------- */ #endif diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_segment_parallel.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_segment_parallel.cc index 8cc9520b6..4cc6a7176 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_segment_parallel.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_segment_parallel.cc @@ -1,189 +1,190 @@ /** * @file test_solid_mechanics_model_segment_parallel.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Tue Jul 27 14:34:13 2010 * * @brief test of the class SolidMechanicsModel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "static_communicator.hh" #include "distributed_synchronizer.hh" #include "mesh_partition_scotch.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER #define CHECK_STRESS int main(int argc, char *argv[]) { akantu::UInt spatial_dimension = 1; #ifdef AKANTU_USE_IOHELPER akantu::ElementType type = akantu::_segment_3; #endif //AKANTU_USE_IOHELPER akantu::UInt max_steps = 10000; akantu::Real time_factor = 0.2; - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::Mesh mesh(spatial_dimension); akantu::StaticCommunicator * comm = akantu::StaticCommunicator::getStaticCommunicator(); akantu::Int psize = comm->getNbProc(); akantu::Int prank = comm->whoAmI(); akantu::debug::setDebugLevel(akantu::dblWarning); akantu::MeshPartition * partition = NULL; if(prank == 0) { akantu::MeshIOMSH mesh_io; mesh_io.read("segment.msh", mesh); partition = new akantu::MeshPartitionScotch(mesh, spatial_dimension); partition->partitionate(psize); } akantu::SolidMechanicsModel model(mesh); model.initParallel(partition); akantu::UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); #ifdef AKANTU_USE_IOHELPER akantu::UInt nb_element = model.getFEM().getMesh().getNbElement(type); #endif //AKANTU_USE_IOHELPER /// model initialization model.initVectors(); /// set vectors to 0 memset(model.getForce().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model.getVelocity().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model.getAcceleration().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); memset(model.getDisplacement().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); model.initExplicit(); model.initModel(); model.readMaterials("material.dat"); model.initMaterials(); std::cout << model.getMaterial(0) << std::endl; model.assembleMassLumped(); #ifdef AKANTU_USE_IOHELPER /// set to 0 only for the first paraview dump memset(model.getResidual().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); #endif //AKANTU_USE_IOHELPER /// boundary conditions for (akantu::UInt i = 0; i < nb_nodes; ++i) { model.getDisplacement().values[spatial_dimension*i] = model.getFEM().getMesh().getNodes().values[i] / 100. ; if(model.getFEM().getMesh().getNodes().values[spatial_dimension*i] <= 1e-15) model.getBoundary().values[i] = true; } memset(model.getForce().values, 0, spatial_dimension*nb_nodes*sizeof(akantu::Real)); // model.synchronizeBoundaries(); akantu::Real time_step = model.getStableTimeStep() * time_factor; std::cout << "Time Step = " << time_step << "s" << std::endl; model.setTimeStep(time_step); #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetParallelContext(prank, psize); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, "line_para"); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(type).values, LINE2, nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, spatial_dimension, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, spatial_dimension, "velocity"); dumper.AddNodeDataField(model.getResidual().values, spatial_dimension, "force"); dumper.AddNodeDataField(model.getAcceleration().values, spatial_dimension, "acceleration"); dumper.AddNodeDataField(model.getMass().values, spatial_dimension, "mass"); double * part = new double[nb_element]; for (unsigned int i = 0; i < nb_element; ++i) part[i] = prank; dumper.AddElemDataField(part, 1, "partitions"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER for(akantu::UInt s = 1; s <= max_steps; ++s) { model.explicitPred(); model.updateResidual(); model.updateAcceleration(); model.explicitCorr(); akantu::Real epot = model.getPotentialEnergy(); akantu::Real ekin = model.getKineticEnergy(); if(prank == 0) { std::cout << s << " " << epot << " " << ekin << " " << epot + ekin << std::endl; } #ifdef AKANTU_USE_IOHELPER // if(s % 100 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER if(s % 10 == 0) std::cerr << "passing step " << s << "/" << max_steps << std::endl; } #ifdef AKANTU_USE_IOHELPER delete [] part; #endif //AKANTU_USE_IOHELPER akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_square.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_square.cc index 5f45a1596..205dcd919 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_square.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_square.cc @@ -1,174 +1,175 @@ /** * @file test_solid_mechanics_model.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Tue Jul 27 14:34:13 2010 * * @brief test of the class SolidMechanicsModel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "solid_mechanics_model.hh" #include "material.hh" #include "fem.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; static void trac(__attribute__ ((unused)) double * position, double * traction, __attribute__ ((unused)) Real * normal, __attribute__ ((unused)) UInt surface_id){ memset(traction,0,sizeof(Real)*4); traction[0] = 1000; traction[3] = 1000; // if(fabs(position[0])< 1e-4){ // traction[0] = -position[1]; // } } int main(int argc, char *argv[]) { - akantu::initialize(&argc,&argv); + akantu::initialize(argc, argv); UInt max_steps = 1000; Real epot, ekin; #ifdef AKANTU_USE_IOHELPER ElementType type = _triangle_3; - UInt para_type = TRIANGLE1; + ElemType para_type = iohelper::TRIANGLE1; #endif //AKANTU_USE_IOHELPER Mesh mesh(2); MeshIOMSH mesh_io; mesh_io.read("square.msh", mesh); SolidMechanicsModel model(mesh); /// model initialization model.initVectors(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); memset(model.getForce().values, 0, 2*nb_nodes*sizeof(Real)); memset(model.getVelocity().values, 0, 2*nb_nodes*sizeof(Real)); memset(model.getAcceleration().values, 0, 2*nb_nodes*sizeof(Real)); memset(model.getDisplacement().values, 0, 2*nb_nodes*sizeof(Real)); memset(model.getResidual().values, 0, 2*nb_nodes*sizeof(Real)); memset(model.getMass().values, 1, nb_nodes*sizeof(Real)); model.initExplicit(); model.initModel(); model.readMaterials("material.dat"); model.initMaterials(); Real time_step = model.getStableTimeStep(); model.setTimeStep(time_step/10.); model.assembleMassLumped(); std::cout << model << std::endl; /// boundary conditions // Real eps = 1e-16; // for (UInt i = 0; i < nb_nodes; ++i) { // model.getDisplacement().values[2*i] = model.getFEM().getMesh().getNodes().values[2*i] / 100.; // if(model.getFEM().getMesh().getNodes().values[2*i] <= eps) { // model.getBoundary().values[2*i ] = true; // if(model.getFEM().getMesh().getNodes().values[2*i + 1] <= eps) // model.getBoundary().values[2*i + 1] = true; // } // if(model.getFEM().getMesh().getNodes().values[2*i + 1] <= eps) { // model.getBoundary().values[2*i + 1] = true; // } // } FEM & fem_boundary = model.getFEMBoundary(); fem_boundary.initShapeFunctions(); fem_boundary.computeNormalsOnControlPoints(); model.computeForcesFromFunction(trac, akantu::_bft_stress); #ifdef AKANTU_USE_IOHELPER - DumperParaview dumper; - dumper.SetMode(BASE64); + iohelper::DumperParaview dumper; + dumper.SetMode(iohelper::BASE64); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, 2, nb_nodes, "coordinates"); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(type).values, - para_type, model.getFEM().getMesh().getNbElement(type), C_MODE); + para_type, model.getFEM().getMesh().getNbElement(type), iohelper::C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, 2, "displacements"); dumper.AddNodeDataField(model.getVelocity().values, 2, "velocity"); dumper.AddNodeDataField(model.getForce().values, 2, "force"); dumper.AddNodeDataField(model.getMass().values, 1, "Mass"); dumper.AddNodeDataField(model.getResidual().values, 2, "residual"); dumper.AddElemDataField(model.getMaterial(0).getStrain(type).values, 4, "strain"); dumper.AddElemDataField(model.getMaterial(0).getStress(type).values, 4, "stress"); dumper.SetEmbeddedValue("displacements", 1); dumper.SetEmbeddedValue("force", 1); dumper.SetEmbeddedValue("residual", 1); dumper.SetEmbeddedValue("velocity", 1); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); #endif //AKANTU_USE_IOHELPER std::ofstream energy; energy.open("energy.csv"); energy << "id,epot,ekin,tot" << std::endl; for(UInt s = 0; s < max_steps; ++s) { model.explicitPred(); model.updateResidual(); model.updateAcceleration(); model.explicitCorr(); epot = model.getPotentialEnergy(); ekin = model.getKineticEnergy(); std::cerr << "passing step " << s << "/" << max_steps << std::endl; energy << s << "," << epot << "," << ekin << "," << epot + ekin << std::endl; #ifdef AKANTU_USE_IOHELPER if(s % 100 == 0) dumper.Dump(); #endif //AKANTU_USE_IOHELPER } energy.close(); finalize(); return EXIT_SUCCESS; } diff --git a/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2.cc b/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2.cc index 97afe6b35..a3c9349b4 100644 --- a/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2.cc +++ b/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2.cc @@ -1,228 +1,229 @@ /** * @file test_structural_mechanics_model_bernoulli_beam_2.cc * @author Fabian Barras <fabian.barras@epfl.ch> * @date Thu May 12 16:34:09 2011 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh_struct.hh" #include "structural_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #define TYPE _bernoulli_beam_2 using namespace akantu; #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; void paraviewInit(Dumper & dumper, const StructuralMechanicsModel & model); void paraviewDump(Dumper & dumper); #endif //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); load[1]= -60000000; } int main(int argc, char *argv[]){ - initialize(&argc, &argv); + initialize(argc, argv); Mesh beams(2); debug::setDebugLevel(dblWarning); /* -------------------------------------------------------------------------- */ // Defining the mesh UInt nb_nodes=101; UInt nb_element=nb_nodes-1; UInt nb_nodes_h=101; UInt nb_nodes_v= nb_nodes-nb_nodes_h; Vector<Real> & nodes = const_cast<Vector<Real> &>(beams.getNodes()); nodes.resize(nb_nodes); beams.addConnecticityType(_bernoulli_beam_2); Vector<UInt> & connectivity = const_cast<Vector<UInt> &>(beams.getConnectivity(_bernoulli_beam_2)); connectivity.resize(nb_element); for(UInt i=0; i<nb_nodes_h; ++i) { nodes(i,0)=2./((Real)nb_nodes_h-1)*i; nodes(i,1)=0; } for(UInt i=nb_nodes_h; i<nb_nodes; ++i) { nodes(i,0)=2; nodes(i,1)=2./((Real)nb_nodes_v)*(i-nb_nodes_h); } /**nodes(0,0)=0; nodes(1,0)=10; nodes(2,0)=18; */ for(UInt i=0; i<nb_element; ++i) { connectivity(i,0)=i; connectivity(i,1)=i+1; } akantu::MeshIOMSHStruct mesh_io; mesh_io.write("b_beam_2.msh", beams); /* -------------------------------------------------------------------------- */ // Defining the forces // akantu::ElementType type = akantu::_bernoulli_beam_2; akantu::StructuralMechanicsModel * model; model = new akantu::StructuralMechanicsModel(beams); model->initModel(); StructuralMaterial mat1; mat1.E=2.05e11; mat1.I=0.00128; mat1.A=0.01; model->addMaterial(mat1); model->initVectors(); model->initImplicitSolver(); // const Real M = 3600; // Momentum at 3 Vector<Real> & forces = model->getForce(); Vector<Real> & displacement = model->getDisplacement(); Vector<bool> & boundary = model->getBoundary(); Vector<UInt> element_material = model->getElementMaterial(_bernoulli_beam_2); forces.clear(); displacement.clear(); model->computeForcesFromFunction(lin_load, akantu::_bft_forces); /**forces(0,2)=-N; forces(nb_nodes-1,2)=N; for (UInt i = 0; i < nb_nodes; ++i) { forces(i,1)=-N/nb_nodes; } */ boundary(0,0) = true; boundary(0,1) = true; //boundary(0,2) = true; //boundary(nb_nodes-1,0) = true; boundary(nb_nodes-1,1) = true; //boundary(nb_nodes-1,2) = true; Real error; model->assembleStiffnessMatrix(); model->getStiffnessMatrix().saveMatrix("Kb.mtx"); UInt count = 0; #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper, *model); #endif 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; model->getStiffnessMatrix().saveMatrix("Ka.mtx"); #ifdef AKANTU_USE_IOHELPER paraviewDump(dumper); #endif } /* -------------------------------------------------------------------------- */ /* Dumper vars */ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ -template <ElementType type> UInt paraviewType(); -template <> UInt paraviewType<_segment_2>() { return LINE1; }; -template <> UInt paraviewType<_segment_3>() { return LINE2; }; -template <> UInt paraviewType<_triangle_3>() { return TRIANGLE1; }; -template <> UInt paraviewType<_triangle_6>() { return TRIANGLE2; }; -template <> UInt paraviewType<_quadrangle_4>() { return QUAD1; }; -template <> UInt paraviewType<_tetrahedron_4>() { return TETRA1; }; -template <> UInt paraviewType<_tetrahedron_10>() { return TETRA2; }; -template <> UInt paraviewType<_hexahedron_8>() { return HEX1; }; -template <> UInt paraviewType<_bernoulli_beam_2>(){ return LINE1; }; +template <ElementType type> ElemType paraviewType(); +template <> ElemType paraviewType<_segment_2>() { return LINE1; }; +template <> ElemType paraviewType<_segment_3>() { return LINE2; }; +template <> ElemType paraviewType<_triangle_3>() { return TRIANGLE1; }; +template <> ElemType paraviewType<_triangle_6>() { return TRIANGLE2; }; +template <> ElemType paraviewType<_quadrangle_4>() { return QUAD1; }; +template <> ElemType paraviewType<_tetrahedron_4>() { return TETRA1; }; +template <> ElemType paraviewType<_tetrahedron_10>() { return TETRA2; }; +template <> ElemType paraviewType<_hexahedron_8>() { return HEX1; }; +template <> ElemType paraviewType<_bernoulli_beam_2>(){ return LINE1; }; /* -------------------------------------------------------------------------- */ void paraviewInit(Dumper & dumper, const StructuralMechanicsModel & model) { UInt spatial_dimension = ElementClass<TYPE>::getSpatialDimension(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); UInt nb_element = model.getFEM().getMesh().getNbElement(TYPE); std::stringstream filename; filename << "beam"; dumper.SetMode(TEXT); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, filename.str().c_str()); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(TYPE).values, paraviewType<TYPE>(), nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, 3, "displacements"); dumper.AddNodeDataField(model.getForce().values, 3, "applied_force"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } /* -------------------------------------------------------------------------- */ #endif diff --git a/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2_complicated.cc b/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2_complicated.cc index c973bb364..83ba7029c 100644 --- a/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2_complicated.cc +++ b/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2_complicated.cc @@ -1,237 +1,238 @@ /** * @file test_structural_mechanics_model_bernoulli_beam_2_complicated.cc * @author Fabian Barras <fabian.barras@epfl.ch> * @date Wed Jun 1 16:06:45 2011 * * @brief A very complicated structure * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh_struct.hh" #include "structural_mechanics_model.hh" #include "material.hh" /* -------------------------------------------------------------------------- */ #define TYPE _bernoulli_beam_2 using namespace akantu; #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; void paraviewInit(Dumper & dumper, const StructuralMechanicsModel & model); void paraviewDump(Dumper & dumper); #endif //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[1]>=0.-Math::getTolerance()) { if ((position[0]<=10.)){ load[1]= -100; } else if (position[0]<=20.){ load[1]= -70; } } } int main(int argc, char *argv[]){ - initialize(&argc, &argv); + initialize(argc, argv); Mesh beams(2); debug::setDebugLevel(dblWarning); /* -------------------------------------------------------------------------- */ // Defining the mesh akantu::MeshIOMSHStruct mesh_io; mesh_io.read("complicated.msh", beams); mesh_io.write("complicated_tata.msh", beams); /* -------------------------------------------------------------------------- */ // Defining the material const akantu::ElementType type = akantu::_bernoulli_beam_2; akantu::StructuralMechanicsModel * model; model = new akantu::StructuralMechanicsModel(beams); StructuralMaterial mat1; mat1.E=3e10; mat1.I=0.0025; mat1.A=0.01; model->addMaterial(mat1); StructuralMaterial mat2 ; mat2.E=3e10; mat2.I=0.003125; mat2.A=0.01; model->addMaterial(mat2); /* -------------------------------------------------------------------------- */ // Defining the forces model->initModel(); model->initVectors(); UInt nb_element = beams.getNbElement(type); for (unsigned int i = 0; i < nb_element; ++i) { model->getElementMaterial(type)(i,0) = beams.getUIntData(type, "tag_0")(i,0) - 1; } Vector<Real> & forces = model->getForce(); Vector<Real> & displacement = model->getDisplacement(); Vector<bool> & boundary = model->getBoundary(); // const Vector<Real> & N_M = model->getStress(_bernoulli_beam_2); // Vector<UInt> & element_material = model->getElementMaterial(_bernoulli_beam_2); forces.clear(); displacement.clear(); model->computeForcesFromFunction(lin_load, akantu::_bft_forces); /* -------------------------------------------------------------------------- */ // Defining the boundary conditions boundary(0,0) = true; boundary(0,1) = true; boundary(3,0) = true; boundary(3,1) = true; boundary(4,0) = true; boundary(4,1) = true; boundary(4,2) = true; boundary(5,0) = true; boundary(5,1) = true; boundary(5,2) = true; //boundary(2,1) = true; //boundary(2,0) = true; //boundary(1,1) = true; //boundary(1,0) = true; /* -------------------------------------------------------------------------- */ // Solve model->initImplicitSolver(); Real error; model->assembleStiffnessMatrix(); model->getStiffnessMatrix().saveMatrix("Kb.mtx"); UInt count = 0; #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper, *model); #endif 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->computeStressOnQuad(); model->getStiffnessMatrix().saveMatrix("Ka.mtx"); std::cout<< " x1 = " << displacement(1,2) << std::endl; std::cout<< " x2 = " << displacement(2,2) << std::endl; #ifdef AKANTU_USE_IOHELPER paraviewDump(dumper); #endif } /* -------------------------------------------------------------------------- */ /* Dumper vars */ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ -template <ElementType type> UInt paraviewType(); -template <> UInt paraviewType<_segment_2>() { return LINE1; }; -template <> UInt paraviewType<_segment_3>() { return LINE2; }; -template <> UInt paraviewType<_triangle_3>() { return TRIANGLE1; }; -template <> UInt paraviewType<_triangle_6>() { return TRIANGLE2; }; -template <> UInt paraviewType<_quadrangle_4>() { return QUAD1; }; -template <> UInt paraviewType<_tetrahedron_4>() { return TETRA1; }; -template <> UInt paraviewType<_tetrahedron_10>() { return TETRA2; }; -template <> UInt paraviewType<_hexahedron_8>() { return HEX1; }; -template <> UInt paraviewType<_bernoulli_beam_2>(){ return BEAM2; }; +template <ElementType type> ElemType paraviewType(); +template <> ElemType paraviewType<_segment_2>() { return LINE1; }; +template <> ElemType paraviewType<_segment_3>() { return LINE2; }; +template <> ElemType paraviewType<_triangle_3>() { return TRIANGLE1; }; +template <> ElemType paraviewType<_triangle_6>() { return TRIANGLE2; }; +template <> ElemType paraviewType<_quadrangle_4>() { return QUAD1; }; +template <> ElemType paraviewType<_tetrahedron_4>() { return TETRA1; }; +template <> ElemType paraviewType<_tetrahedron_10>() { return TETRA2; }; +template <> ElemType paraviewType<_hexahedron_8>() { return HEX1; }; +template <> ElemType paraviewType<_bernoulli_beam_2>(){ return BEAM2; }; /* -------------------------------------------------------------------------- */ void paraviewInit(Dumper & dumper, const StructuralMechanicsModel & model) { UInt spatial_dimension = ElementClass<TYPE>::getSpatialDimension(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); UInt nb_element = model.getFEM().getMesh().getNbElement(TYPE); std::stringstream filename; filename << "beam"; dumper.SetMode(TEXT); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, filename.str().c_str()); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(TYPE).values, paraviewType<TYPE>(), nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, 3, "displacements"); dumper.AddNodeDataField(model.getForce().values, 3, "applied_force"); dumper.AddElemDataField(model.getStress(_bernoulli_beam_2).values, 2, "stress"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } /* -------------------------------------------------------------------------- */ #endif diff --git a/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2_exemple_1_1.cc b/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2_exemple_1_1.cc index 493ad4044..69426fc0c 100644 --- a/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2_exemple_1_1.cc +++ b/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_bernoulli_beam_2_exemple_1_1.cc @@ -1,256 +1,257 @@ /** * @file test_structural_mechanics_model_bernoulli_beam_2_exemple_1_1.cc * @author Fabian Barras <fabian.barras@epfl.ch> * @date Tue May 31 19:10:26 2011 * * @brief Computation of the analytical exemple 1.1 in the TGC vol 6 * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #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; #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; void paraviewInit(Dumper & dumper, const StructuralMechanicsModel & model); void paraviewDump(Dumper & dumper); #endif //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); + initialize(argc, argv); Mesh beams(2); debug::setDebugLevel(dblWarning); /* -------------------------------------------------------------------------- */ // Defining the mesh UInt nb_nodes=401; UInt nb_nodes_1=200; UInt nb_nodes_2=nb_nodes-nb_nodes_1 - 1; UInt nb_element=nb_nodes-1; Vector<Real> & nodes = const_cast<Vector<Real> &>(beams.getNodes()); nodes.resize(nb_nodes); beams.addConnecticityType(_bernoulli_beam_2); Vector<UInt> & connectivity = const_cast<Vector<UInt> &>(beams.getConnectivity(_bernoulli_beam_2)); connectivity.resize(nb_element); for(UInt i=0; i<nb_nodes; ++i) { nodes(i,1)=0; } for (UInt i = 0; i < nb_nodes_1; ++i) { nodes(i,0)=10.*i/((Real)nb_nodes_1); } nodes(nb_nodes_1,0)=10; for (UInt i = 0; i < nb_nodes_2; ++i) { nodes(nb_nodes_1 + i + 1,0)=10+ 8.*(i+1)/((Real)nb_nodes_2); } for(UInt i=0; i<nb_element; ++i) { connectivity(i,0)=i; connectivity(i,1)=i+1; } akantu::MeshIOMSH mesh_io; mesh_io.write("b_beam_2.msh", beams); /* -------------------------------------------------------------------------- */ // Defining the materials // akantu::ElementType type = akantu::_bernoulli_beam_2; akantu::StructuralMechanicsModel * model; model = new akantu::StructuralMechanicsModel(beams); StructuralMaterial mat1; mat1.E=3e10; mat1.I=0.0025; mat1.A=0.01; model->addMaterial(mat1); StructuralMaterial mat2 ; mat2.E=3e10; mat2.I=0.00128; mat2.A=0.01; model->addMaterial(mat2); /* -------------------------------------------------------------------------- */ // Defining the forces model->initModel(); model->initVectors(); const Real M = -3600; // Momentum at 3 Vector<Real> & forces = model->getForce(); Vector<Real> & displacement = model->getDisplacement(); Vector<bool> & boundary = model->getBoundary(); const Vector<Real> & N_M = model->getStress(_bernoulli_beam_2); Vector<UInt> & 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(lin_load, akantu::_bft_forces); /* -------------------------------------------------------------------------- */ // 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 model->initImplicitSolver(); Real error; model->assembleStiffnessMatrix(); model->getStiffnessMatrix().saveMatrix("Kb.mtx"); UInt count = 0; #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; paraviewInit(dumper, *model); #endif 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->computeStressOnQuad(); model->getStiffnessMatrix().saveMatrix("Ka.mtx"); 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; #ifdef AKANTU_USE_IOHELPER paraviewDump(dumper); #endif } /* -------------------------------------------------------------------------- */ /* Dumper vars */ /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ -template <ElementType type> UInt paraviewType(); -template <> UInt paraviewType<_segment_2>() { return LINE1; }; -template <> UInt paraviewType<_segment_3>() { return LINE2; }; -template <> UInt paraviewType<_triangle_3>() { return TRIANGLE1; }; -template <> UInt paraviewType<_triangle_6>() { return TRIANGLE2; }; -template <> UInt paraviewType<_quadrangle_4>() { return QUAD1; }; -template <> UInt paraviewType<_tetrahedron_4>() { return TETRA1; }; -template <> UInt paraviewType<_tetrahedron_10>() { return TETRA2; }; -template <> UInt paraviewType<_hexahedron_8>() { return HEX1; }; -template <> UInt paraviewType<_bernoulli_beam_2>(){ return BEAM2; }; +template <ElementType type> ElemType paraviewType(); +template <> ElemType paraviewType<_segment_2>() { return LINE1; }; +template <> ElemType paraviewType<_segment_3>() { return LINE2; }; +template <> ElemType paraviewType<_triangle_3>() { return TRIANGLE1; }; +template <> ElemType paraviewType<_triangle_6>() { return TRIANGLE2; }; +template <> ElemType paraviewType<_quadrangle_4>() { return QUAD1; }; +template <> ElemType paraviewType<_tetrahedron_4>() { return TETRA1; }; +template <> ElemType paraviewType<_tetrahedron_10>() { return TETRA2; }; +template <> ElemType paraviewType<_hexahedron_8>() { return HEX1; }; +template <> ElemType paraviewType<_bernoulli_beam_2>(){ return BEAM2; }; /* -------------------------------------------------------------------------- */ void paraviewInit(Dumper & dumper, const StructuralMechanicsModel & model) { UInt spatial_dimension = ElementClass<TYPE>::getSpatialDimension(); UInt nb_nodes = model.getFEM().getMesh().getNbNodes(); UInt nb_element = model.getFEM().getMesh().getNbElement(TYPE); std::stringstream filename; filename << "beam"; dumper.SetMode(TEXT); dumper.SetPoints(model.getFEM().getMesh().getNodes().values, spatial_dimension, nb_nodes, filename.str().c_str()); dumper.SetConnectivity((int *)model.getFEM().getMesh().getConnectivity(TYPE).values, paraviewType<TYPE>(), nb_element, C_MODE); dumper.AddNodeDataField(model.getDisplacement().values, 3, "displacements"); dumper.AddNodeDataField(model.getForce().values, 3, "applied_force"); dumper.AddElemDataField(model.getStress(_bernoulli_beam_2).values, 2, "stress"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); } /* -------------------------------------------------------------------------- */ void paraviewDump(Dumper & dumper) { dumper.Dump(); } /* -------------------------------------------------------------------------- */ #endif diff --git a/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_boundary_bernoulli_beam_2.cc b/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_boundary_bernoulli_beam_2.cc index 64586ad31..3830e6506 100644 --- a/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_boundary_bernoulli_beam_2.cc +++ b/test/test_model/test_structural_mechanics_model/test_structural_mechanics_model_boundary_bernoulli_beam_2.cc @@ -1,118 +1,119 @@ /** * @file test_structural_mechanics_model_boundary_bernoulli_beam_2.cc * @author Fabian Barras <fabian.barras@epfl.ch> * @date Thu May 26 12:52:54 2011 * * @brief Test the computation of linear load * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <limits> #include <fstream> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "structural_mechanics_model.hh" /* -------------------------------------------------------------------------- */ #define TYPE _bernoulli_beam_2 using namespace akantu; #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; void paraviewInit(Dumper & dumper, const StructuralMechanicsModel & model); void paraviewDump(Dumper & dumper); #endif static void lin_load(double * position, double * load, __attribute__ ((unused)) Real * normal, __attribute__ ((unused)) UInt surface_id){ memset(load,0,sizeof(Real)*3); //load[1]= (position[0])*200000000; load[1]= 200000000; } int main(int argc, char *argv[]){ - initialize(&argc, &argv); + initialize(argc, argv); Mesh beams(2); debug::setDebugLevel(dblWarning); /* -------------------------------------------------------------------------- */ // Defining the mesh UInt nb_nodes=2; UInt nb_element=nb_nodes-1; UInt nb_nodes_h=2; UInt nb_nodes_v= nb_nodes-nb_nodes_h; Vector<Real> & nodes = const_cast<Vector<Real> &>(beams.getNodes()); nodes.resize(nb_nodes); beams.addConnecticityType(_bernoulli_beam_2); Vector<UInt> & connectivity = const_cast<Vector<UInt> &>(beams.getConnectivity(_bernoulli_beam_2)); connectivity.resize(nb_element); for(UInt i=0; i<nb_nodes_h; ++i) { nodes(i,0)=2./((Real)nb_nodes_h)*i; nodes(i,1)=0; } for(UInt i=nb_nodes_h; i<nb_nodes; ++i) { nodes(i,0)=2; nodes(i,1)=2./((Real)nb_nodes_v)*(i-nb_nodes_h); } for(UInt i=0; i<nb_element; ++i) { connectivity(i,0)=i; connectivity(i,1)=i+1; } akantu::MeshIOMSH mesh_io; mesh_io.write("b_beam_2.msh", beams); /* -------------------------------------------------------------------------- */ // Defining the forces // akantu::ElementType type = akantu::_bernoulli_beam_2; akantu::StructuralMechanicsModel * model; model = new akantu::StructuralMechanicsModel(beams); model->initModel(); model->initVectors(); Vector<Real> & forces = model->getForce(); forces.clear(); model->computeForcesFromFunction(lin_load, akantu::_bft_forces); } diff --git a/test/test_solver/test_solver_mumps.cc b/test/test_solver/test_solver_mumps.cc index 0af210eb8..4dabf963a 100644 --- a/test/test_solver/test_solver_mumps.cc +++ b/test/test_solver/test_solver_mumps.cc @@ -1,87 +1,87 @@ /** * @file test_solver_mumps.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Sun Dec 12 20:20:32 2010 * * @brief simple test of the mumps solver interface * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "solver_mumps.hh" #include "static_communicator.hh" /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); // akantu::debug::setDebugLevel(akantu::dblDump); akantu::StaticCommunicator * comm = akantu::StaticCommunicator::getStaticCommunicator(); akantu::UInt n = 10 * comm->getNbProc(); akantu::SparseMatrix * sparse_matrix = new akantu::SparseMatrix(n, akantu::_symmetric, 1, "hand"); akantu::UInt i_start = comm->whoAmI() * 10; for(akantu::UInt i = i_start; i < i_start + 10; ++i) { sparse_matrix->addToProfile(i, i); sparse_matrix->addToMatrix (i, i, 1./((i+1) * 10.)); } // sparse_matrix->addToProfile(9, 8); // sparse_matrix->addToMatrix(9, 8, -1.); // sparse_matrix->addToMatrix(9, 9, -1.); akantu::Solver * solver = new akantu::SolverMumps(*sparse_matrix); akantu::Vector<akantu::Real> * rhs = NULL; if(comm->whoAmI() == 0) { rhs = new akantu::Vector<akantu::Real>(n, 1); rhs->clear(); for(akantu::UInt i = 0; i < n; ++i) { rhs->values[i] = 1.; } solver->setRHS(*rhs); rhs->clear(); } // std::stringstream sstr; sstr << "solver_matrix.mtx" << comm->whoAmI(); // sparse_matrix->saveMatrix(sstr.str()); solver->initialize(); solver->solve(*rhs); if(comm->whoAmI() == 0) { akantu::debug::setDebugLevel(akantu::dblDump); std::cout << *rhs << std::endl; akantu::debug::setDebugLevel(akantu::dblWarning); } delete solver; if (rhs) delete rhs; delete sparse_matrix; akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_solver/test_sparse_matrix_assemble.cc b/test/test_solver/test_sparse_matrix_assemble.cc index 3ebc68006..31ae12ee2 100644 --- a/test/test_solver/test_sparse_matrix_assemble.cc +++ b/test/test_solver/test_sparse_matrix_assemble.cc @@ -1,78 +1,78 @@ /** * @file test_sparse_matrix_assemble.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Nov 5 11:13:33 2010 * * @brief test the assembling method of the SparseMatrix class * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <cstdlib> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "sparse_matrix.hh" #include "dof_synchronizer.hh" /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::UInt spatial_dimension = 2; akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("triangle.msh", mesh); akantu::UInt nb_nodes = mesh.getNbNodes(); akantu::SparseMatrix sparse_matrix(nb_nodes * spatial_dimension, akantu::_symmetric, spatial_dimension); akantu::DOFSynchronizer dof_synchronizer(mesh, spatial_dimension); dof_synchronizer.initGlobalDOFEquationNumbers(); sparse_matrix.buildProfile(mesh, dof_synchronizer); // const akantu::Mesh::ConnectivityTypeList & type_list = mesh.getConnectivityTypeList(); // akantu::Mesh::ConnectivityTypeList::const_iterator it; // for(it = type_list.begin(); it != type_list.end(); ++it) { // if(mesh.getSpatialDimension(*it) != spatial_dimension) continue; // akantu::UInt nb_element = mesh.getNbElement(*it); // akantu::UInt nb_nodes_per_element = mesh.getNbNodesPerElement(*it); // akantu::Element element(*it); // akantu::UInt m = nb_nodes_per_element * spatial_dimension; // akantu::Vector<akantu::Real> local_mat(m, m, 1, "local_mat"); // for(akantu::UInt e = 0; e < nb_element; ++e) { // element.element = e; // sparse_matrix.addToMatrix(local_mat.values, element, nb_nodes_per_element); // } // } sparse_matrix.saveMatrix("matrix.mtx"); akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_solver/test_sparse_matrix_product.cc b/test/test_solver/test_sparse_matrix_product.cc index 65f9493cf..555349643 100644 --- a/test/test_solver/test_sparse_matrix_product.cc +++ b/test/test_solver/test_sparse_matrix_product.cc @@ -1,145 +1,145 @@ /** * @file test_sparse_matrix_product.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Mon Jun 6 15:06:47 2011 * * @brief test the matrix vector product in parallel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io_msh.hh" #include "mesh_partition_scotch.hh" #include "distributed_synchronizer.hh" #include "sparse_matrix.hh" #include "dof_synchronizer.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - initialize(&argc, &argv); + initialize(argc, argv); const UInt spatial_dimension = 2; const UInt nb_dof = 3; StaticCommunicator * comm = akantu::StaticCommunicator::getStaticCommunicator(); Int psize = comm->getNbProc(); Int prank = comm->whoAmI(); Mesh mesh(spatial_dimension); /* ------------------------------------------------------------------------ */ /* Parallel initialization */ /* ------------------------------------------------------------------------ */ DistributedSynchronizer * communicator; MeshPartition * partition; if(prank == 0) { MeshIOMSH mesh_io; mesh_io.read("bar.msh", mesh); std::cout << "Partitioning mesh..." << std::endl; partition = new akantu::MeshPartitionScotch(mesh, spatial_dimension); partition->partitionate(psize); communicator = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, partition); delete partition; } else { communicator = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, NULL); } UInt nb_nodes = mesh.getNbNodes(); UInt nb_global_node = mesh.getNbGlobalNodes(); // Vector<Int> equation_number(nb_nodes, nb_dof); // for (UInt n = 0; n < nb_nodes; ++n) { // UInt real_n = mesh.getNodeGlobalId(n); // bool is_local_node = !(mesh.isPureGhostNode(n)); // for (UInt d = 0; d < nb_dof; ++d) { // UInt global_eq_num = (is_local_node ? real_n : nb_global_node + real_n) * nb_dof + d; // equation_number(n, d) = global_eq_num; // } // } if (prank == 0) std::cout << "Creating a SparseMatrix" << std::endl; SparseMatrix sparse_matrix(nb_global_node * nb_dof, _symmetric, nb_dof, "matrix"); DOFSynchronizer dof_synchronizer(mesh, nb_dof); dof_synchronizer.initGlobalDOFEquationNumbers(); sparse_matrix.buildProfile(mesh, dof_synchronizer); Vector<Real> dof_vector(nb_nodes, nb_dof, "vector"); if (prank == 0) std::cout << "Filling the matrix" << std::endl; UInt nz = sparse_matrix.getNbNonZero(); const Vector<Int> & irn = sparse_matrix.getIRN(); const Vector<Int> & jcn = sparse_matrix.getJCN(); for (UInt i = 0; i < nz; ++i) { sparse_matrix.addToMatrix(irn(i) - 1, jcn(i) - 1, 1.); } std::stringstream str; str << "Matrix_" << prank << ".mtx"; sparse_matrix.saveMatrix(str.str()); for (UInt n = 0; n < nb_nodes; ++n) { for (UInt d = 0; d < nb_dof; ++d) { dof_vector(n,d) = 1.; } } if (prank == 0) std::cout << "Computing x = A * x" << std::endl; dof_vector *= sparse_matrix; if (prank == 0) std::cout << "Lumping the matrix" << std::endl; Vector<Real> lumped(0,nb_dof); sparse_matrix.lump(lumped); if (prank == 0) std::cout << "Gathering the results on proc 0" << std::endl; if(psize > 1) { const_cast<DOFSynchronizer &>(sparse_matrix.getDOFSynchronizer()).initScatterGatherCommunicationScheme(); if(prank == 0) { Vector<Real> gathered(0, nb_dof); Vector<Real> lump_gathered(0, nb_dof); sparse_matrix.getDOFSynchronizer().gather(dof_vector, 0, &gathered); sparse_matrix.getDOFSynchronizer().gather(lumped, 0, &lump_gathered); debug::setDebugLevel(dblTest); std::cout << gathered << std::endl; std::cout << lump_gathered << std::endl; debug::setDebugLevel(dblWarning); } else { sparse_matrix.getDOFSynchronizer().gather(dof_vector, 0); sparse_matrix.getDOFSynchronizer().gather(lumped, 0); } } else { debug::setDebugLevel(dblTest); std::cout << dof_vector << std::endl; std::cout << lumped << std::endl; debug::setDebugLevel(dblWarning); } finalize(); return 0; } diff --git a/test/test_solver/test_sparse_matrix_profile.cc b/test/test_solver/test_sparse_matrix_profile.cc index 329fae166..e00888c95 100644 --- a/test/test_solver/test_sparse_matrix_profile.cc +++ b/test/test_solver/test_sparse_matrix_profile.cc @@ -1,97 +1,97 @@ /** * @file test_sparse_matrix_profile.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Nov 5 11:13:33 2010 * * @brief test the profile generation of the SparseMatrix class * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <cstdlib> /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "sparse_matrix.hh" #include "dof_synchronizer.hh" #ifdef AKANTU_USE_SCOTCH #include "mesh_partition_scotch.hh" #endif /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::UInt spatial_dimension = 2; akantu::Mesh mesh(spatial_dimension); akantu::MeshIOMSH mesh_io; mesh_io.read("triangle.msh", mesh); akantu::SparseMatrix sparse_matrix_hand(10, akantu::_symmetric, 1, "hand"); for(akantu::UInt i = 0; i < 10; ++i) { sparse_matrix_hand.addToProfile(i, i); } sparse_matrix_hand.addToProfile(0,9); for(akantu::UInt i = 0; i < 10; ++i) { sparse_matrix_hand.addToMatrix(i, i, i*10); } sparse_matrix_hand.addToMatrix(0,9, 100); sparse_matrix_hand.saveProfile("profile_hand.mtx"); sparse_matrix_hand.saveMatrix("matrix_hand.mtx"); /* ------------------------------------------------------------------------ */ akantu::UInt nb_nodes = mesh.getNbNodes(); akantu::SparseMatrix sparse_matrix(nb_nodes * spatial_dimension, akantu::_symmetric, spatial_dimension, "mesh"); akantu::DOFSynchronizer dof_synchronizer(mesh, spatial_dimension); dof_synchronizer.initGlobalDOFEquationNumbers(); sparse_matrix.buildProfile(mesh, dof_synchronizer); sparse_matrix.saveProfile("profile.mtx"); /* ------------------------------------------------------------------------ */ #ifdef AKANTU_USE_SCOTCH mesh_io.write("triangle_breorder.msh", mesh); akantu::MeshPartition * partition = new akantu::MeshPartitionScotch(mesh, spatial_dimension); partition->reorder(); delete partition; akantu::DOFSynchronizer dof_synchronizer_re(mesh, spatial_dimension); dof_synchronizer_re.initGlobalDOFEquationNumbers(); sparse_matrix.buildProfile(mesh, dof_synchronizer_re); sparse_matrix.saveProfile("profile_reorder.mtx"); mesh_io.write("triangle_reorder.msh", mesh); #endif akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_solver/test_sparse_matrix_profile_parallel.cc b/test/test_solver/test_sparse_matrix_profile_parallel.cc index 147cc4401..4ab24db10 100644 --- a/test/test_solver/test_sparse_matrix_profile_parallel.cc +++ b/test/test_solver/test_sparse_matrix_profile_parallel.cc @@ -1,110 +1,110 @@ /** * @file test_sparse_matrix_profile_parallel.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Feb 3 13:05:27 2011 * * @brief test the sparse matrix class in parallel * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io_msh.hh" #include "mesh_partition_scotch.hh" #include "communicator.hh" #include "sparse_matrix.hh" #include "solver_mumps.hh" /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* Main */ /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); int dim = 2; //#ifdef AKANTU_USE_IOHELPER //akantu::ElementType type = akantu::_triangle_6; //#endif //AKANTU_USE_IOHELPER akantu::Mesh mesh(dim); // akantu::debug::setDebugLevel(akantu::dblDump); akantu::StaticCommunicator * comm = akantu::StaticCommunicator::getStaticCommunicator(); akantu::Int psize = comm->getNbProc(); akantu::Int prank = comm->whoAmI(); akantu::UInt n = 0; /* ------------------------------------------------------------------------ */ /* Parallel initialization */ /* ------------------------------------------------------------------------ */ akantu::Communicator * communicator; if(prank == 0) { akantu::MeshIOMSH mesh_io; mesh_io.read("triangle.msh", mesh); akantu::MeshPartition * partition = new akantu::MeshPartitionScotch(mesh, dim); // partition->reorder(); mesh_io.write("triangle_reorder.msh", mesh); n = mesh.getNbNodes(); partition->partitionate(psize); communicator = akantu::Communicator::createCommunicatorDistributeMesh(mesh, partition); delete partition; } else { communicator = akantu::Communicator::createCommunicatorDistributeMesh(mesh, NULL); } std::cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << mesh.getNbGlobalNodes() << std::endl; akantu::SparseMatrix sparse_matrix(mesh, akantu::_symmetric, 2, "mesh"); sparse_matrix.buildProfile(); akantu::Solver * solver = new akantu::SolverMumps(sparse_matrix); if(prank == 0) { for(akantu::UInt i = 0; i < n; ++i) { solver->getRHS().values[i] = 1.; } } akantu::debug::setDebugLevel(akantu::dblDump); solver->initialize(); std::stringstream sstr; sstr << "profile_" << prank << ".mtx"; sparse_matrix.saveProfile(sstr.str()); akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_static_memory/test_static_memory.cc b/test/test_static_memory/test_static_memory.cc index ece6b25e9..275368158 100644 --- a/test/test_static_memory/test_static_memory.cc +++ b/test/test_static_memory/test_static_memory.cc @@ -1,54 +1,54 @@ /** * @file test_static_memory.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Fri Jun 11 11:55:54 2010 * * @brief unit test for the StaticMemory class * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include <iostream> /* -------------------------------------------------------------------------- */ #include "aka_static_memory.hh" #include "aka_vector.hh" /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); akantu::StaticMemory * st_mem = akantu::StaticMemory::getStaticMemory(); akantu::Vector<int> & test_int = st_mem->smalloc<int>(0, "test_int", 1000, 3); test_int.resize(1050); test_int.resize(2000); std::cout << *st_mem << std::endl; st_mem->sfree(0, "test_int"); akantu::finalize(); exit(EXIT_SUCCESS); } diff --git a/test/test_surface_extraction/test_surface_extraction_tetrahedron_4.cc b/test/test_surface_extraction/test_surface_extraction_tetrahedron_4.cc index b01970805..cad501ab1 100644 --- a/test/test_surface_extraction/test_surface_extraction_tetrahedron_4.cc +++ b/test/test_surface_extraction/test_surface_extraction_tetrahedron_4.cc @@ -1,89 +1,90 @@ /** * @file test_surface_extraction_3d.cc * @author Leonardo Snozzi <leonardo.snozzi@epfl.ch> * @date Mon Oct 25 11:40:12 2010 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { int dim = 3; - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); Mesh mesh(dim); MeshIOMSH mesh_io; mesh_io.read("cubes.msh", mesh); MeshUtils::buildFacets(mesh,1,0); MeshUtils::buildSurfaceID(mesh); unsigned int nb_nodes = mesh.getNbNodes(); #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-surface-extraction"); dumper.SetConnectivity((int*)mesh.getConnectivity(_tetrahedron_4).values, TETRA1, mesh.getNbElement(_tetrahedron_4), C_MODE); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); DumperParaview dumper_surface; dumper_surface.SetMode(TEXT); dumper_surface.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-surface-extraction_boundary"); dumper_surface.SetConnectivity((int *)mesh.getConnectivity(_triangle_3).values, TRIANGLE1, mesh.getNbElement(_triangle_3), C_MODE); double * surf_id = new double [mesh.getSurfaceID(_triangle_3).getSize()]; for (UInt i = 0; i < mesh.getSurfaceID(_triangle_3).getSize(); ++i) surf_id[i] = (double)mesh.getSurfaceID(_triangle_3).values[i]; dumper_surface.AddElemDataField(surf_id, 1, "surface_id"); dumper_surface.SetPrefix("paraview/"); dumper_surface.Init(); dumper_surface.Dump(); delete [] surf_id; #endif //AKANTU_USE_IOHELPER finalize(); return EXIT_SUCCESS; } diff --git a/test/test_surface_extraction/test_surface_extraction_triangle_3.cc b/test/test_surface_extraction/test_surface_extraction_triangle_3.cc index e04556eed..0681d425e 100644 --- a/test/test_surface_extraction/test_surface_extraction_triangle_3.cc +++ b/test/test_surface_extraction/test_surface_extraction_triangle_3.cc @@ -1,89 +1,90 @@ /** * @file test_surface_extraction_2d.cc * @author Leonardo Snozzi <leonardo.snozzi@epfl.ch> * @date Mon Oct 25 09:47:15 2010 * * @brief * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model.hh" #include "material.hh" #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; int main(int argc, char *argv[]) { int dim = 2; - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); Mesh mesh(dim); MeshIOMSH mesh_io; mesh_io.read("squares.msh", mesh); MeshUtils::buildFacets(mesh, 1, 0); MeshUtils::buildSurfaceID(mesh); unsigned int nb_nodes = mesh.getNbNodes(); #ifdef AKANTU_USE_IOHELPER DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-surface-extraction"); dumper.SetConnectivity((int*)mesh.getConnectivity(_triangle_3).values, TRIANGLE1, mesh.getNbElement(_triangle_3), C_MODE); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); DumperParaview dumper_surface; dumper_surface.SetMode(TEXT); dumper_surface.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-surface-extraction_boundary"); dumper_surface.SetConnectivity((int *)mesh.getConnectivity(_segment_2).values, LINE1, mesh.getNbElement(_segment_2), C_MODE); double * surf_id = new double [mesh.getSurfaceID(_segment_2).getSize()]; for (UInt i = 0; i < mesh.getSurfaceID(_segment_2).getSize(); ++i) surf_id[i] = (double)mesh.getSurfaceID(_segment_2).values[i]; dumper_surface.AddElemDataField(surf_id, 1, "surface_id"); dumper_surface.SetPrefix("paraview/"); dumper_surface.Init(); dumper_surface.Dump(); delete [] surf_id; #endif //AKANTU_USE_IOHELPER finalize(); return EXIT_SUCCESS; } diff --git a/test/test_synchronizer/test_dof_synchronizer.cc b/test/test_synchronizer/test_dof_synchronizer.cc index 0bab0dc7f..7c441006a 100644 --- a/test/test_synchronizer/test_dof_synchronizer.cc +++ b/test/test_synchronizer/test_dof_synchronizer.cc @@ -1,228 +1,228 @@ /** * @file test_dof_synchronizer.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Wed Jun 1 09:49:46 2011 * * @brief Test the functionality of the DOFSynchronizer class * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "dof_synchronizer.hh" #include "mesh_partition_scotch.hh" #include "mesh_io.hh" #include "static_communicator.hh" #include "distributed_synchronizer.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" #endif //AKANTU_USE_IOHELPER /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { const UInt spatial_dimension = 3; debug::setDebugLevel(dblDebug); - initialize(&argc, &argv); + initialize(argc, argv); StaticCommunicator * comm = akantu::StaticCommunicator::getStaticCommunicator(); Int psize = comm->getNbProc(); Int prank = comm->whoAmI(); Mesh mesh(spatial_dimension); /* ------------------------------------------------------------------------ */ /* Parallel initialization */ /* ------------------------------------------------------------------------ */ DistributedSynchronizer * communicator; MeshPartition * partition; if(prank == 0) { MeshIOMSH mesh_io; mesh_io.read("bar.msh", mesh); std::cout << "Partitioning mesh..." << std::endl; partition = new akantu::MeshPartitionScotch(mesh, spatial_dimension); partition->partitionate(psize); communicator = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, partition); delete partition; } else { communicator = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, NULL); } UInt nb_nodes = mesh.getNbNodes(); Vector<Real> dof_vector(nb_nodes, spatial_dimension, "Test vector"); std::cout << "Initializing the synchronizer" << std::endl; DOFSynchronizer dof_synchronizer(mesh, spatial_dimension); /* ------------------------------------------------------------------------ */ /* test the sznchroniyation */ /* ------------------------------------------------------------------------ */ for (UInt n = 0; n < nb_nodes; ++n) { UInt gn = mesh.getNodeGlobalId(n); for (UInt d = 0; d < spatial_dimension; ++d) { if(mesh.isMasterNode(n)) dof_vector(n,d) = gn*spatial_dimension + d; else if(mesh.isLocalNode(n)) dof_vector(n,d) = - (double) (gn*spatial_dimension + d); else if(mesh.isSlaveNode(n)) dof_vector(n,d) = NAN; else dof_vector(n,d) = -NAN; } } std::cout << "Synchronizing a dof vector" << std::endl; dof_synchronizer.synchronize(dof_vector); for (UInt n = 0; n < nb_nodes; ++n) { UInt gn = mesh.getNodeGlobalId(n); for (UInt d = 0; d < spatial_dimension; ++d) { if(!((mesh.isMasterNode(n) && dof_vector(n,d) == (gn*spatial_dimension + d)) || (mesh.isLocalNode(n) && dof_vector(n,d) == - (double) (gn*spatial_dimension + d)) || (mesh.isSlaveNode(n) && dof_vector(n,d) == (gn*spatial_dimension + d)) || (mesh.isPureGhostNode(n)) ) ) { debug::setDebugLevel(dblTest); std::cout << "prank : " << prank << " (node " << gn*spatial_dimension + d << "[" << n * spatial_dimension + d << "]) - " << (mesh.isMasterNode(n) && dof_vector(n,d) == (gn*spatial_dimension + d)) << " " << (mesh.isLocalNode(n) && dof_vector(n,d) == - (double) (gn*spatial_dimension + d)) << " " << (mesh.isSlaveNode(n) && dof_vector(n,d) == (gn*spatial_dimension + d)) << " " << (mesh.isPureGhostNode(n)) << std::endl; std::cout << dof_vector << dof_synchronizer.getDOFGlobalIDs() << dof_synchronizer.getDOFTypes() << std::endl; debug::setDebugLevel(dblDebug); return EXIT_FAILURE; } } } /* ------------------------------------------------------------------------ */ /* test the reduce operation */ /* ------------------------------------------------------------------------ */ for (UInt n = 0; n < nb_nodes; ++n) { for (UInt d = 0; d < spatial_dimension; ++d) { if(mesh.isMasterNode(n)) dof_vector(n,d) = 1; else if(mesh.isLocalNode(n)) dof_vector(n,d) = -300; else if(mesh.isSlaveNode(n)) dof_vector(n,d) = 2; else dof_vector(n,d) = -500; } } std::cout << "Reducing a dof vector" << std::endl; dof_synchronizer.reduceSynchronize<AddOperation<Real> >(dof_vector); for (UInt n = 0; n < nb_nodes; ++n) { for (UInt d = 0; d < spatial_dimension; ++d) { if(!((mesh.isMasterNode(n) && dof_vector(n,d) >= 3) || (mesh.isLocalNode(n) && dof_vector(n,d) == -300) || (mesh.isSlaveNode(n) && dof_vector(n,d) >= 3) || (mesh.isPureGhostNode(n) && dof_vector(n,d) == -500) ) ) { debug::setDebugLevel(dblTest); std::cout << dof_vector << dof_synchronizer.getDOFGlobalIDs() << dof_synchronizer.getDOFTypes() << std::endl; debug::setDebugLevel(dblDebug); return EXIT_FAILURE; } } } /* ------------------------------------------------------------------------ */ /* test the gather/scatter */ /* ------------------------------------------------------------------------ */ dof_vector.clear(); for (UInt n = 0; n < nb_nodes; ++n) { UInt gn = mesh.getNodeGlobalId(n); for (UInt d = 0; d < spatial_dimension; ++d) { if(mesh.isMasterNode(n)) dof_vector(n,d) = gn * spatial_dimension + d; else if(mesh.isLocalNode(n)) dof_vector(n,d) = - (double) (gn * spatial_dimension + d); else if(mesh.isSlaveNode(n)) dof_vector(n,d) = NAN; else dof_vector(n,d) = -NAN; } } std::cout << "Initializing the gather/scatter information" << std::endl; dof_synchronizer.initScatterGatherCommunicationScheme(); std::cout << "Gathering on proc 0" << std::endl; if(prank == 0) { UInt nb_global_nodes = mesh.getNbGlobalNodes(); Vector<Real> gathered(nb_global_nodes, spatial_dimension, "gathered information"); dof_synchronizer.gather(dof_vector, 0, &gathered); for (UInt n = 0; n < nb_nodes; ++n) { for (UInt d = 0; d < spatial_dimension; ++d) { if(std::abs(gathered(n,d)) != n * spatial_dimension + d) { debug::setDebugLevel(dblTest); std::cout << gathered << std::endl; std::cout << dof_vector << dof_synchronizer.getDOFGlobalIDs() << dof_synchronizer.getDOFTypes() << std::endl; debug::setDebugLevel(dblDebug); return EXIT_FAILURE; } } } } else { dof_synchronizer.gather(dof_vector, 0); } dof_vector.clear(); std::cout << "Scattering from proc 0" << std::endl; if(prank == 0) { UInt nb_global_nodes = mesh.getNbGlobalNodes(); Vector<Real> to_scatter(nb_global_nodes, spatial_dimension, "to scatter information"); for (UInt d = 0; d < nb_global_nodes * spatial_dimension; ++d) { to_scatter.values[d] = d; } dof_synchronizer.scatter(dof_vector, 0, &to_scatter); } else { dof_synchronizer.scatter(dof_vector, 0); } for (UInt n = 0; n < nb_nodes; ++n) { UInt gn = mesh.getNodeGlobalId(n); for (UInt d = 0; d < spatial_dimension; ++d) { if(!mesh.isPureGhostNode(n) && !(dof_vector(n,d) == (gn * spatial_dimension + d))) { debug::setDebugLevel(dblTest); std::cout << dof_vector << dof_synchronizer.getDOFGlobalIDs() << dof_synchronizer.getDOFTypes() << std::endl; debug::setDebugLevel(dblDebug); return EXIT_FAILURE; } } } delete communicator; finalize(); return 0; } diff --git a/test/test_synchronizer/test_grid_synchronizer.cc b/test/test_synchronizer/test_grid_synchronizer.cc index 3703b2b28..393002a1f 100644 --- a/test/test_synchronizer/test_grid_synchronizer.cc +++ b/test/test_synchronizer/test_grid_synchronizer.cc @@ -1,230 +1,230 @@ /** * @file test_grid_synchronizer.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Mon Nov 7 11:58:02 2011 * * @brief test the GridSynchronizer object * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "aka_grid.hh" #include "mesh.hh" #include "mesh_io.hh" #include "grid_synchronizer.hh" #include "mesh_partition.hh" #include "synchronizer_registry.hh" using namespace akantu; class TestAccessor : public DataAccessor { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: TestAccessor(const Mesh & mesh); ~TestAccessor(); AKANTU_GET_MACRO_BY_ELEMENT_TYPE_CONST(GhostBarycenter, ghost_barycenter, Real); /* ------------------------------------------------------------------------ */ /* Ghost Synchronizer inherited members */ /* ------------------------------------------------------------------------ */ protected: virtual UInt getNbDataToPack(const Element & element, SynchronizationTag tag) const; virtual UInt getNbDataToUnpack(const Element & element, SynchronizationTag tag) const; virtual void packData(CommunicationBuffer & buffer, const Element & element, SynchronizationTag tag) const; virtual void unpackData(CommunicationBuffer & buffer, const Element & element, SynchronizationTag tag); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: std::string id; ByElementTypeReal ghost_barycenter; const Mesh & mesh; }; /* -------------------------------------------------------------------------- */ /* TestSynchronizer implementation */ /* -------------------------------------------------------------------------- */ TestAccessor::TestAccessor(const Mesh & mesh) : ghost_barycenter("ghost_barycenter", id), mesh(mesh) { UInt spatial_dimension = mesh.getSpatialDimension(); id = "test_synchronizer"; Mesh::ConnectivityTypeList::const_iterator it; const Mesh::ConnectivityTypeList & ghost_type_list = mesh.getConnectivityTypeList(_ghost); for(it = ghost_type_list.begin(); it != ghost_type_list.end(); ++it) { if(Mesh::getSpatialDimension(*it) != spatial_dimension) continue; UInt nb_ghost_element = mesh.getNbElement(*it,_ghost); ghost_barycenter.alloc(nb_ghost_element, spatial_dimension, *it); } } TestAccessor::~TestAccessor() { } UInt TestAccessor::getNbDataToPack(const Element & element, __attribute__ ((unused)) SynchronizationTag tag) const { return Mesh::getSpatialDimension(element.type) * sizeof(Real); } UInt TestAccessor::getNbDataToUnpack(const Element & element, __attribute__ ((unused)) SynchronizationTag tag) const { return Mesh::getSpatialDimension(element.type) * sizeof(Real); } void TestAccessor::packData(CommunicationBuffer & buffer, const Element & element, __attribute__ ((unused)) SynchronizationTag tag) const { UInt spatial_dimension = Mesh::getSpatialDimension(element.type); types::RVector bary(spatial_dimension); mesh.getBarycenter(element.element, element.type, bary.storage()); buffer << bary; } void TestAccessor::unpackData(CommunicationBuffer & buffer, const Element & element, __attribute__ ((unused)) SynchronizationTag tag) { UInt spatial_dimension = Mesh::getSpatialDimension(element.type); Vector<Real>::iterator<types::RVector> bary = ghost_barycenter(element.type).begin(spatial_dimension); buffer >> bary[element.element]; } int main(int argc, char *argv[]) { - akantu::initialize(&argc, &argv); + akantu::initialize(argc, argv); UInt spatial_dimension = 2; // ElementType type = _triangle_3; Mesh mesh(spatial_dimension); StaticCommunicator * comm = StaticCommunicator::getStaticCommunicator(); Int psize = comm->getNbProc(); Int prank = comm->whoAmI(); DistributedSynchronizer * communicator; if(prank == 0) { MeshIOMSH mesh_io; mesh_io.read("triangle.msh", mesh); MeshPartition * partition = new MeshPartitionScotch(mesh, spatial_dimension); partition->partitionate(psize); communicator = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, partition); delete partition; } else { communicator = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, NULL); } comm->barrier(); AKANTU_DEBUG_INFO("Creating TestAccessor"); TestAccessor test_accessor(mesh); SynchronizerRegistry synch_registry(test_accessor); mesh.computeBoundingBox(); Real lower_bounds[spatial_dimension]; Real upper_bounds[spatial_dimension]; mesh.getLocalLowerBounds(lower_bounds); mesh.getLocalUpperBounds(upper_bounds); Real spacing[spatial_dimension]; for (UInt i = 0; i < spatial_dimension; ++i) { spacing[i] = (upper_bounds[i] - lower_bounds[i]) / 100.; } RegularGrid<Element> grid(spatial_dimension, lower_bounds, upper_bounds, spacing); GhostType ghost_type = _not_ghost; Mesh::type_iterator it = mesh.firstType(spatial_dimension, ghost_type); Mesh::type_iterator last_type = mesh.lastType(spatial_dimension, ghost_type); ByElementTypeReal barycenters("", "", 0); mesh.initByElementTypeVector(barycenters, spatial_dimension, 0); // first generate the quad points coordinate and count the number of points per cell for(; it != last_type; ++it) { UInt nb_element = mesh.getNbElement(*it); Vector<Real> & barycenter = barycenters(*it); barycenter.resize(nb_element); Vector<Real>::iterator<types::RVector> bary_it = barycenter.begin(spatial_dimension); for (UInt elem = 0; elem < nb_element; ++elem) { mesh.getBarycenter(elem, *it, bary_it->storage()); grid.count(*bary_it); ++bary_it; } } Element e; e.ghost_type = ghost_type; // second insert the point in the cells grid.beginInsertions(); it = mesh.firstType(spatial_dimension, ghost_type); for(; it != last_type; ++it) { UInt nb_element = mesh.getNbElement(*it); e.type = *it; Vector<Real> & barycenter = barycenters(*it); Vector<Real>::iterator<types::RVector> bary_it = barycenter.begin(spatial_dimension); for (UInt elem = 0; elem < nb_element; ++elem) { e.element = elem; grid.insert(e, *bary_it); ++bary_it; } } grid.endInsertions(); GridSynchronizer * grid_communicator = GridSynchronizer::createGridSynchronizer(mesh, grid); synch_registry.registerSynchronizer(*grid_communicator,_gst_test); AKANTU_DEBUG_INFO("Synchronizing tag"); synch_registry.synchronize(_gst_test); akantu::finalize(); return EXIT_SUCCESS; } diff --git a/test/test_synchronizer/test_synchronizer_communication.cc b/test/test_synchronizer/test_synchronizer_communication.cc index 823f21634..baa401178 100644 --- a/test/test_synchronizer/test_synchronizer_communication.cc +++ b/test/test_synchronizer/test_synchronizer_communication.cc @@ -1,269 +1,270 @@ /** * @file test_synchronizer_communication.cc * @author Nicolas Richart <nicolas.richart@epfl.ch> * @date Thu Aug 19 13:05:27 2010 * * @brief test to synchronize barycenters * * @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 <http://www.gnu.org/licenses/>. * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "static_communicator.hh" #include "distributed_synchronizer.hh" #include "synchronizer_registry.hh" #include "mesh.hh" #include "mesh_io_msh.hh" #include "mesh_partition_scotch.hh" #include "communication_buffer.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER -# include "io_helper.h" +# include "io_helper.hh" +using namespace iohelper; #endif //AKANTU_USE_IOHELPER using namespace akantu; class TestAccessor : public DataAccessor { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: TestAccessor(const Mesh & mesh); ~TestAccessor(); AKANTU_GET_MACRO_BY_ELEMENT_TYPE_CONST(GhostBarycenter, ghost_barycenter, Real); /* ------------------------------------------------------------------------ */ /* Ghost Synchronizer inherited members */ /* ------------------------------------------------------------------------ */ protected: virtual UInt getNbDataToPack(const Element & element, SynchronizationTag tag) const; virtual UInt getNbDataToUnpack(const Element & element, SynchronizationTag tag) const; virtual void packData(CommunicationBuffer & buffer, const Element & element, SynchronizationTag tag) const; virtual void unpackData(CommunicationBuffer & buffer, const Element & element, SynchronizationTag tag); virtual UInt getNbDataToPack(SynchronizationTag tag) const; virtual UInt getNbDataToUnpack(SynchronizationTag tag) const; virtual void packData(CommunicationBuffer & buffer, const UInt index, SynchronizationTag tag) const; virtual void unpackData(CommunicationBuffer & buffer, const UInt index, SynchronizationTag tag); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ protected: std::string id; ByElementTypeReal ghost_barycenter; const Mesh & mesh; }; /* -------------------------------------------------------------------------- */ /* TestSynchronizer implementation */ /* -------------------------------------------------------------------------- */ TestAccessor::TestAccessor(const Mesh & mesh) : ghost_barycenter("ghost_barycenter", id), mesh(mesh) { UInt spatial_dimension = mesh.getSpatialDimension(); id = "test_synchronizer"; Mesh::ConnectivityTypeList::const_iterator it; const Mesh::ConnectivityTypeList & ghost_type_list = mesh.getConnectivityTypeList(_ghost); for(it = ghost_type_list.begin(); it != ghost_type_list.end(); ++it) { if(Mesh::getSpatialDimension(*it) != spatial_dimension) continue; UInt nb_ghost_element = mesh.getNbElement(*it,_ghost); ghost_barycenter.alloc(nb_ghost_element, spatial_dimension, *it); } } TestAccessor::~TestAccessor() { } UInt TestAccessor::getNbDataToPack(const Element & element, __attribute__ ((unused)) SynchronizationTag tag) const { return Mesh::getSpatialDimension(element.type) * sizeof(Real); } UInt TestAccessor::getNbDataToUnpack(const Element & element, __attribute__ ((unused)) SynchronizationTag tag) const { return Mesh::getSpatialDimension(element.type) * sizeof(Real); } void TestAccessor::packData(CommunicationBuffer & buffer, const Element & element, __attribute__ ((unused)) SynchronizationTag tag) const { UInt spatial_dimension = Mesh::getSpatialDimension(element.type); types::RVector bary(spatial_dimension); mesh.getBarycenter(element.element, element.type, bary.storage()); buffer << bary; } void TestAccessor::unpackData(CommunicationBuffer & buffer, const Element & element, __attribute__ ((unused)) SynchronizationTag tag) { UInt spatial_dimension = Mesh::getSpatialDimension(element.type); Vector<Real>::iterator<types::RVector> bary = ghost_barycenter(element.type).begin(spatial_dimension); buffer >> bary[element.element]; } UInt TestAccessor::getNbDataToPack(__attribute__ ((unused)) SynchronizationTag tag) const { return 0; } UInt TestAccessor::getNbDataToUnpack(__attribute__ ((unused)) SynchronizationTag tag) const { return 0; } void TestAccessor::packData(__attribute__ ((unused)) CommunicationBuffer & buffer, __attribute__ ((unused)) const UInt index, __attribute__ ((unused)) SynchronizationTag tag) const { } void TestAccessor::unpackData(__attribute__ ((unused)) CommunicationBuffer & buffer, __attribute__ ((unused)) const UInt index, __attribute__ ((unused)) SynchronizationTag tag) { } /* -------------------------------------------------------------------------- */ /* Main */ /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - initialize(&argc, &argv); + initialize(argc, argv); int dim = 2; ElementType type = _triangle_3; Mesh mesh(dim); StaticCommunicator * comm = StaticCommunicator::getStaticCommunicator(); Int psize = comm->getNbProc(); Int prank = comm->whoAmI(); DistributedSynchronizer * communicator; if(prank == 0) { MeshIOMSH mesh_io; mesh_io.read("triangle.msh", mesh); MeshPartition * partition = new MeshPartitionScotch(mesh, dim); partition->partitionate(psize); communicator = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, partition); delete partition; } else { communicator = DistributedSynchronizer::createDistributedSynchronizerMesh(mesh, NULL); } comm->barrier(); AKANTU_DEBUG_INFO("Creating TestAccessor"); TestAccessor test_accessor(mesh); SynchronizerRegistry synch_registry(test_accessor); synch_registry.registerSynchronizer(*communicator,_gst_test); AKANTU_DEBUG_INFO("Synchronizing tag"); synch_registry.synchronize(_gst_test); Mesh::ConnectivityTypeList::const_iterator it; const Mesh::ConnectivityTypeList & ghost_type_list = mesh.getConnectivityTypeList(_ghost); for(it = ghost_type_list.begin(); it != ghost_type_list.end(); ++it) { if(Mesh::getSpatialDimension(*it) != mesh.getSpatialDimension()) continue; UInt spatial_dimension = Mesh::getSpatialDimension(*it); UInt nb_ghost_element = mesh.getNbElement(*it,_ghost); for (UInt el = 0; el < nb_ghost_element; ++el) { Real barycenter[spatial_dimension]; mesh.getBarycenter(el, *it, barycenter, _ghost); for (UInt i = 0; i < spatial_dimension; ++i) { if(fabs(barycenter[i] - test_accessor.getGhostBarycenter(*it).values[el * spatial_dimension + i]) > std::numeric_limits<Real>::epsilon()) AKANTU_DEBUG_ERROR("The barycenter of ghost element " << el << " on proc " << prank << " does not match the one get during synchronisation" ); } } } #ifdef AKANTU_USE_IOHELPER unsigned int nb_nodes = mesh.getNbNodes(); unsigned int nb_element = mesh.getNbElement(type); DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetParallelContext(prank, psize); dumper.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-scotch-partition"); dumper.SetConnectivity((int*) mesh.getConnectivity(type).values, TRIANGLE1, nb_element, C_MODE); double * part = new double[nb_element]; for (unsigned int i = 0; i < nb_element; ++i) part[i] = prank; dumper.AddElemDataField(part, 1, "partitions"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); delete [] part; unsigned int nb_ghost_element = mesh.getNbElement(type,_ghost); DumperParaview dumper_ghost; dumper_ghost.SetMode(TEXT); dumper_ghost.SetParallelContext(prank, psize); dumper_ghost.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-scotch-partition_ghost"); dumper_ghost.SetConnectivity((int*) mesh.getConnectivity(type,_ghost).values, TRIANGLE1, nb_ghost_element, C_MODE); part = new double[nb_ghost_element]; for (unsigned int i = 0; i < nb_ghost_element; ++i) part[i] = prank; dumper_ghost.AddElemDataField(part, 1, "partitions"); dumper_ghost.SetPrefix("paraview/"); dumper_ghost.Init(); dumper_ghost.Dump(); delete [] part; #endif //AKANTU_USE_IOHELPER finalize(); return EXIT_SUCCESS; }