diff --git a/CMakeLists.txt b/CMakeLists.txt index e1b86817a..f8f80448c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,244 +1,255 @@ #=============================================================================== # @file CMakeLists.txt # @author Nicolas Richart # @date Fri Jun 11 09:46:59 2010 # # @section LICENSE # # # # @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 "${AKANTU_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries.") #=============================================================================== # Version Number #=============================================================================== # AKANTU version number. An even minor number corresponds to releases. set(AKANTU_MAJOR_VERSION 0) set(AKANTU_MINOR_VERSION 1) set(AKANTU_BUILD_VERSION 0) set(AKANTU_VERSION "${AKANTU_MAJOR_VERSION}.${AKANTU_MINOR_VERSION}.${AKANTU_BUILD_VERSION}" ) # 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 #=============================================================================== # Debug option(AKANTU_DEBUG "Compiles akantu with the debug messages" ON) if(NOT AKANTU_DEBUG) add_definitions(-DAKANTU_NDEBUG) endif(NOT AKANTU_DEBUG) # IOHelper option(AKANTU_USE_IOHELPER "Add IOHelper support in akantu" OFF) if(AKANTU_USE_IOHELPER) find_package(IOHelper REQUIRED) if(IOHELPER_FOUND) add_definitions(-DAKANTU_USE_IOHELPER) set(AKANTU_EXTERNAL_LIB_INCLUDE_PATH ${AKANTU_EXTERNAL_LIB_INCLUDE_PATH} ${IOHELPER_INCLUDE_PATH} ) set(AKANTU_EXTERNAL_LIBRARIES ${AKANTU_EXTERNAL_LIBRARIES} ${IOHELPER_LIBRARIES} ) endif(IOHELPER_FOUND) endif(AKANTU_USE_IOHELPER) # MPI set(AKANTU_MPI_ON FALSE) option(AKANTU_USE_MPI "Add MPI support in akantu" OFF) if(AKANTU_USE_MPI) find_package(MPI REQUIRED) if(MPI_FOUND) add_definitions(-DAKANTU_USE_MPI) set(AKANTU_EXTERNAL_LIB_INCLUDE_PATH ${AKANTU_EXTERNAL_LIB_INCLUDE_PATH} ${MPI_INCLUDE_PATH} ) set(AKANTU_EXTERNAL_LIBRARIES ${AKANTU_EXTERNAL_LIBRARIES} ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY} ) set(AKANTU_MPI_ON TRUE) endif(MPI_FOUND) endif(AKANTU_USE_MPI) # Scotch set(AKANTU_SCOTCH_ON FALSE) option(AKANTU_USE_SCOTCH "Add Scotch support in akantu" OFF) if(AKANTU_USE_SCOTCH) find_package(Scotch REQUIRED) if(SCOTCH_FOUND) add_definitions(-DAKANTU_USE_SCOTCH) set(AKANTU_EXTERNAL_LIB_INCLUDE_PATH ${AKANTU_EXTERNAL_LIB_INCLUDE_PATH} ${SCOTCH_INCLUDE_PATH} ) set(AKANTU_EXTERNAL_LIBRARIES ${AKANTU_EXTERNAL_LIBRARIES} ${SCOTCH_LIBRARIES} ) set(AKANTU_SCOTCH_ON TRUE) endif(SCOTCH_FOUND) endif(AKANTU_USE_SCOTCH) # Doxygen OPTION(AKANTU_DOCUMENTATION "Build source documentation using Doxygen." OFF) # BLAS set(AKANTU_BLAS_ON FALSE) option(AKANTU_USE_BLAS "Use BLAS for arithmetic operations" OFF) if(AKANTU_USE_BLAS) enable_language(Fortran) find_package(BLAS) if(BLAS_FOUND) add_definitions(-DAKANTU_USE_CBLAS) set(AKANTU_EXTERNAL_LIBRARIES ${AKANTU_EXTERNAL_LIBRARIES} ${BLAS_LIBRARIES} ) set(AKANTU_BLAS_ON TRUE) endif(BLAS_FOUND) endif(AKANTU_USE_BLAS) #=============================================================================== # Library #=============================================================================== set(AKANTU_COMMON_SRC common/aka_common.cc common/aka_error.cc common/aka_extern.cc common/aka_static_memory.cc common/aka_memory.cc common/aka_vector.cc common/aka_math.cc fem/mesh.cc fem/fem.cc fem/element_class.cc # model/integration_scheme/central_difference.cc model/solid_mechanics/solid_mechanics_model.cc model/solid_mechanics/solid_mechanics_model_mass.cc model/solid_mechanics/material.cc model/solid_mechanics/materials/material_elastic.cc model/solid_mechanics/contact.cc model/solid_mechanics/contact_search.cc model/solid_mechanics/contact_neighbor_structure.cc mesh_utils/mesh_io.cc mesh_utils/mesh_io/mesh_io_msh.cc mesh_utils/mesh_partition.cc mesh_utils/mesh_utils.cc synchronizer/ghost_synchronizer.cc synchronizer/synchronizer.cc synchronizer/communicator.cc synchronizer/static_communicator.cc ) if(AKANTU_USE_MPI AND MPI_FOUND) set(AKANTU_COMMON_SRC ${AKANTU_COMMON_SRC} synchronizer/static_communicator_mpi.cc ) endif(AKANTU_USE_MPI AND MPI_FOUND) if(AKANTU_SCOTCH_ON) set(AKANTU_COMMON_SRC ${AKANTU_COMMON_SRC} mesh_utils/mesh_partition/mesh_partition_scotch.cc ) endif(AKANTU_SCOTCH_ON) set(AKANTU_INCLUDE_DIRS common fem/ mesh_utils/ mesh_utils/mesh_io/ mesh_utils/mesh_partition/ model/ model/integration_scheme model/solid_mechanics model/solid_mechanics/materials model/solid_mechanics/contact synchronizer/ ) include_directories( ${AKANTU_INCLUDE_DIRS} ${AKANTU_EXTERNAL_LIB_INCLUDE_PATH} ) add_library(akantu ${AKANTU_COMMON_SRC}) set_target_properties(akantu PROPERTIES ${AKANTU_LIBRARY_PROPERTIES}) #=========================================================================== # 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 #=============================================================================== option(AKANTU_TESTS "Activate tests" OFF) if(AKANTU_TESTS) find_package(GMSH REQUIRED) add_subdirectory(test) endif(AKANTU_TESTS) + + + +#=============================================================================== +# Examples +#=============================================================================== + +option(AKANTU_EXAMPLES "Activate examples" OFF) +if(AKANTU_EXAMPLES) + add_subdirectory(examples) +endif(AKANTU_EXAMPLES) diff --git a/common/aka_common.hh b/common/aka_common.hh index 6046cb643..5e8b62f43 100644 --- a/common/aka_common.hh +++ b/common/aka_common.hh @@ -1,253 +1,255 @@ /** * @file aka_common.hh * @author Nicolas Richart * @date Fri Jun 11 09:48:06 2010 * * @namespace akantu * * @section LICENSE * * \ * * @section DESCRIPTION * * All common things to be included in the projects files * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_COMMON_HH__ #define __AKANTU_COMMON_HH__ /* -------------------------------------------------------------------------- */ #include #include #include /* -------------------------------------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include /* -------------------------------------------------------------------------- */ #define __BEGIN_AKANTU__ namespace akantu { #define __END_AKANTU__ } /* -------------------------------------------------------------------------- */ #include "aka_error.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ /* Common types */ /* -------------------------------------------------------------------------- */ typedef double Real; typedef unsigned int UInt; typedef int Int; typedef std::string ID; #ifdef AKANTU_NDEBUG static const Real REAL_INIT_VALUE = 0; #else static const Real REAL_INIT_VALUE = std::numeric_limits::quiet_NaN(); #endif /* -------------------------------------------------------------------------- */ /* Memory types */ /* -------------------------------------------------------------------------- */ typedef UInt MemoryID; typedef ID VectorID; /* -------------------------------------------------------------------------- */ /* Mesh/FEM/Model types */ /* -------------------------------------------------------------------------- */ typedef ID MeshID; typedef ID FEMID; typedef ID ModelID; typedef ID MaterialID; typedef UInt Surface; enum ElementType { _not_defined = 0, _line_1 = 1, // implemented _line_2 = 2, // implemented _triangle_1 = 3, // implemented _triangle_2 = 4, // implemented _tetrahedra_1 = 5, // implemented _tetrahedra_2 = 6, _max_element_type, _point }; enum MaterialType { _elastic = 0, _max_material_type }; /* -------------------------------------------------------------------------- */ /* Contact */ /* -------------------------------------------------------------------------- */ typedef ID ContactID; typedef ID ContactSearchID; typedef ID ContactNeighborStructureID; enum ContactType { - _ct_not_defined = 0 + _ct_not_defined = 0, + _ct_2d_expli = 1 }; enum ContactSearchType { - _cst_not_defined = 0 + _cst_not_defined = 0, + _cst_2d_expli = 1 }; enum ContactNeighborStructureType { _cnst_not_defined = 0 }; /* -------------------------------------------------------------------------- */ /* Ghosts handling */ /* -------------------------------------------------------------------------- */ typedef ID SynchronizerID; /// @CommunicatorType type of communication method to use enum CommunicatorType { _communicator_mpi, _communicator_dummy }; /// @enum GhostSynchronizationTag type of synchronizations enum GhostSynchronizationTag { /// SolidMechanicsModel tags _gst_smm_mass, /// synchronization of the SolidMechanicsModel.mass _gst_smm_residual, /// synchronization of the SolidMechanicsModel.current_position _gst_smm_boundary, /// synchronization of the boundary, forces, velocities and displacement /// 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 " " /* -------------------------------------------------------------------------- */ #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(name, variable, type) \ inline type get##name (const ::akantu::ElementType & el_type) const { \ AKANTU_DEBUG_IN(); \ AKANTU_DEBUG_ASSERT(variable[el_type] != NULL, \ "No " << #variable << " of type " \ << el_type << " in " << id); \ AKANTU_DEBUG_OUT(); \ return *variable[el_type]; \ } /* -------------------------------------------------------------------------- */ //! standard output stream operator for ElementType inline std::ostream & operator <<(std::ostream & stream, ElementType type) { switch(type) { case _line_1 : stream << "line_1" ; break; case _line_2 : stream << "line_2" ; break; case _triangle_1 : stream << "triangle_1" ; break; case _triangle_2 : stream << "triangle_2" ; break; case _tetrahedra_1 : stream << "tetrahedra_1"; break; case _tetrahedra_2 : stream << "tetrahedra_2"; break; case _not_defined : stream << "undefined" ; break; case _max_element_type : stream << "ElementType(" << (int) type << ")"; break; case _point : stream << "point"; break; } return stream; } /* -------------------------------------------------------------------------- */ 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__ #endif /* __AKANTU_COMMON_HH__ */ diff --git a/examples/2d_compression/2d_compression.cc b/examples/2d_compression/2d_compression.cc new file mode 100644 index 000000000..f000e7a87 --- /dev/null +++ b/examples/2d_compression/2d_compression.cc @@ -0,0 +1,224 @@ +/** + * @file 2d_compression.cc + * @author Leo + * @date Thu Sep 30 17:05:00 2010 + * + * @brief 2d dynamic explicit compression test with akantu + * + * @section LICENSE + * + * + * + */ + +/* -------------------------------------------------------------------------- */ +#include +#include + +/* -------------------------------------------------------------------------- */ +#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 "io_helper.h" + +//using namespace akantu; + +static void setInitialConditions(akantu::SolidMechanicsModel *); +static void setBoundaryConditions(akantu::SolidMechanicsModel *, akantu::Vector *); +static void Apply_Displacement(akantu::SolidMechanicsModel *, akantu::Vector *, akantu::Real); +static void reduceVelocities(akantu::SolidMechanicsModel *, akantu::Real); +static void InitParaview(akantu::SolidMechanicsModel *); + +DumperParaview dumper; + + +int main(int argc, char *argv[]) +{ + akantu::UInt spatial_dimension = 2; + akantu::UInt max_steps = 30000; + akantu::Real time_factor = 0.2; + + akantu::Mesh mesh(spatial_dimension); + akantu::MeshIOMSH mesh_io; + mesh_io.read("square_2d.msh", mesh); + + akantu::SolidMechanicsModel * model = new akantu::SolidMechanicsModel(mesh); + + akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); + akantu::UInt nb_elements = model->getFEM().getMesh().getNbElement(akantu::_triangle_1); + + /// model initialization + model->initVectors(); + + model->readMaterials("material.dat"); + model->initMaterials(); + + model->initModel(); + std::cout << model->getMaterial(0) << std::endl; + + model->assembleMass(); + + + /// Paraview Helper + memset(model->getResidual().values, 0, + spatial_dimension*nb_nodes*sizeof(akantu::Real)); + memset(model->getMaterial(0).getStrain(akantu::_triangle_1).values, 0, + spatial_dimension*spatial_dimension*nb_elements*sizeof(akantu::Real)); + memset(model->getMaterial(0).getStress(akantu::_triangle_1).values, 0, + spatial_dimension*spatial_dimension*nb_elements*sizeof(akantu::Real)); + + + /// boundary and initial conditions + setInitialConditions(model); + akantu::Vector * face_node = new akantu::Vector(0, 2, "face_node"); + setBoundaryConditions(model, face_node); + + /// Paraview Helper + InitParaview(model); + + akantu::Real time_step = model->getStableTimeStep() * time_factor; + std::cout << "Time Step = " << time_step << "s" << std::endl; + model->setTimeStep(time_step); + + model->setPotentialEnergyFlagOn(); + for(akantu::UInt s = 1; s <= max_steps; ++s) { + + if(s<=100) + Apply_Displacement(model, face_node, -0.01/100); + + model->explicitPred(); + + model->updateResidual(); + + model->updateAcceleration(); + model->explicitCorr(); + + if(s % 200 == 0) + dumper.Dump(); + + if(s%100 == 0 && s>499) + reduceVelocities(model, 0.95); + + if(s % 100 == 0) std::cout << "passing step " << s << "/" << max_steps << std::endl; + } + + delete face_node; + return EXIT_SUCCESS; +} + + + +/************************** + ** Static Functions ** + **************************/ + +static void setInitialConditions(akantu::SolidMechanicsModel * model) +{ + akantu::UInt spatial_dimension = model->getSpatialDimension(); + akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); + /// 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)); +} + + +static void setBoundaryConditions(akantu::SolidMechanicsModel * model, akantu::Vector * face_node) +{ + akantu::Real eps = 1e-16; + akantu::Real x_min, x_max; + akantu::Real * coord = model->getFEM().getMesh().getNodes().values; + bool * id = model->getBoundary().values; + akantu::Real y_min = std::numeric_limits::max(); + akantu::Real y_max = std::numeric_limits::min(); + akantu::UInt temp[2] = {0,0}, i; + akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); + akantu::UInt spatial_dimension = model->getSpatialDimension(); + + for(i = 0; i < nb_nodes; ++i) { + y_min = (coord[spatial_dimension*i+1] < y_min) ? coord[spatial_dimension*i+1] : y_min; + y_max = (coord[spatial_dimension*i+1] > y_max) ? coord[spatial_dimension*i+1] : y_max; + } + + for (i = 0; i < nb_nodes; ++i) { + if(coord[spatial_dimension*i+1]-eps <= y_min) { + id[spatial_dimension*i+1] = true; + temp[0] = 1; // face id + temp[1] = i; // node id + face_node->push_back(temp); + continue; + } + + if(coord[spatial_dimension*i+1]+eps >= y_max) + id[spatial_dimension*i+1] = true; + } + +} + +static void Apply_Displacement(akantu::SolidMechanicsModel * model, akantu::Vector * face_node, akantu::Real delta) +{ + akantu::Real * disp_val = model->getDisplacement().values; + const akantu::UInt nb_face_nodes = face_node->getSize(); + akantu::Real * dis_val = model->getDisplacement().values; + + for(akantu::UInt i=0; ivalues[2*i] == 1) { /// Node on top surface + dis_val[2*(face_node->values[2*i+1])+1] += delta; + } +} + + +// Artificial damping of velocities in order to reach a global static equilibrium +static void reduceVelocities(akantu::SolidMechanicsModel * model, akantu::Real ratio) +{ + akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); + akantu::Real * velocities = model->getVelocity().values; + + if(ratio>1.) { + fprintf(stderr,"**error** in Reduce_Velocities ratio bigger than 1!\n"); + exit(-1); + } + + for(akantu::UInt i =0; igetSpatialDimension(); + akantu::UInt nb_nodes = model->getFEM().getMesh().getNbNodes(); + akantu::UInt nb_elements = model->getFEM().getMesh().getNbElement(akantu::_triangle_1); + + dumper.SetMode(TEXT); + dumper.SetPoints(model->getFEM().getMesh().getNodes().values, + spatial_dimension, nb_nodes, "coordinates"); + dumper.SetConnectivity((int *)model->getFEM().getMesh().getConnectivity(akantu::_triangle_1).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(akantu::_triangle_1).values, + spatial_dimension*spatial_dimension, "strain"); + dumper.AddElemDataField(model->getMaterial(0).getStress(akantu::_triangle_1).values, + spatial_dimension*spatial_dimension, "stress"); + dumper.SetEmbeddedValue("displacements", 1); + dumper.SetPrefix("paraview/"); + dumper.Init(); + dumper.Dump(); +} diff --git a/examples/2d_compression/CMakeLists.txt b/examples/2d_compression/CMakeLists.txt new file mode 100644 index 000000000..00b1989bd --- /dev/null +++ b/examples/2d_compression/CMakeLists.txt @@ -0,0 +1,27 @@ +#=============================================================================== +# @file CMakeLists.txt +# @author Leo +# @date Fri Sep 29 16:46:30 2010 ...più precisi di così +# +# @section LICENSE +# +# +# +# @section DESCRIPTION +# +#=============================================================================== + +#=============================================================================== +add_mesh(2d_compression_mesh square_2d.geo 2 1) + +register_test(2d_compression + 2d_compression.cc) +add_dependencies(2d_compression + 2d_compression_mesh) + +#=============================================================================== +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/material.dat + ${CMAKE_CURRENT_BINARY_DIR}/material.dat + COPYONLY + ) \ No newline at end of file diff --git a/examples/2d_compression/material.dat b/examples/2d_compression/material.dat new file mode 100644 index 000000000..781c77d73 --- /dev/null +++ b/examples/2d_compression/material.dat @@ -0,0 +1,6 @@ +material elastic [ + name = steel + rho = 7800 # density + E = 2.1e11 # young's modulus + nu = 0.3 # poisson's ratio +] diff --git a/examples/2d_compression/square_2d.geo b/examples/2d_compression/square_2d.geo new file mode 100644 index 000000000..7146ce074 --- /dev/null +++ b/examples/2d_compression/square_2d.geo @@ -0,0 +1,26 @@ +// Element size +h = 0.05; + +// Dimension of square +L = 1; + +// ------------------------------------------ +// Geometry +// ------------------------------------------ + +// Points +Point(1) = {0, 0, 0, h}; +Point(2) = {L, 0, 0, h}; +Point(3) = {L, L, 0, h}; +Point(4) = {0, L, 0, h}; + +// Lines +Line(1) = {4, 1}; +Line(2) = {1, 2}; +Line(3) = {2, 3}; +Line(4) = {3, 4}; + +// Geometric and Physical Surface +Line Loop(6) = {4, 1, 2, 3}; +Plane Surface(6) = {6}; +Physical Surface(7) = {6}; diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 000000000..156d8ff08 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,80 @@ +#=============================================================================== +# @file CMakeLists.txt +# @author Nicolas Richart +# @author Guillaume Anciaux +# @date Fri Jun 11 09:46:59 2010 +# +# @section LICENSE +# +# +# +# @section DESCRIPTION +# +#=============================================================================== + +#=============================================================================== +# Tests +#=============================================================================== + +option(AKANTU_BUILD_ALL_EXAMPLES "Build all examples") + +#=============================================================================== +macro(register_test test_name source_list) + add_executable(${test_name} ${source_list}) + target_link_libraries(${test_name} akantu ${AKANTU_EXTERNAL_LIBRARIES}) +endmacro() + +#=============================================================================== +macro(add_mesh MESH_TARGET GEO_FILE DIM ORDER) + set(_geo_file ${CMAKE_CURRENT_SOURCE_DIR}/${GEO_FILE}) + get_filename_component(_msh_file "${GEO_FILE}" NAME_WE) + set(_msh_file ${CMAKE_CURRENT_BINARY_DIR}/${_msh_file}.msh) + if(EXISTS ${_geo_file}) + add_custom_command( + OUTPUT ${_msh_file} + DEPENDS ${_geo_file} + COMMAND gmsh + ARGS -${DIM} -order ${ORDER} -optimize -o ${_msh_file} ${_geo_file} 2>&1 > /dev/null + ) + add_custom_target(${MESH_TARGET} + DEPENDS ${_msh_file}) + else(EXISTS ${_geo_file}) + message(FATAL_ERROR "File ${_geo_file} not found") + endif(EXISTS ${_geo_file}) +endmacro() + +#=============================================================================== +macro(add_example example_name desc) + string(TOUPPER ${example_name} upper_name) + + option(AKANTU_BUILD_${upper_name} "${desc}") + mark_as_advanced(AKANTU_BUILD_${upper_name}) + + if(AKANTU_BUILD_ALL_TESTS) + set(AKANTU_BUILD_${upper_name}_OLD + ${AKANTU_BUILD_${upper_name}} + CACHE INTERNAL "${desc}" FORCE) + + set(AKANTU_BUILD_${upper_name} ON + CACHE INTERNAL "${desc}" FORCE) + else(AKANTU_BUILD_ALL_TESTS) + if(DEFINED AKANTU_BUILD_${upper_name}_OLD) + set(AKANTU_BUILD_${upper_name} + ${AKANTU_BUILD_${upper_name}_OLD} + CACHE BOOL "${desc}" FORCE) + + unset(BUILD_${upper_name}_OLD + CACHE) + endif(DEFINED AKANTU_BUILD_${upper_name}_OLD) + endif(AKANTU_BUILD_ALL_TESTS) + + if(AKANTU_BUILD_${upper_name}) + add_subdirectory(${example_name}) + endif(AKANTU_BUILD_${upper_name}) + +endmacro() + +#=============================================================================== +# List of tests +#=============================================================================== +add_example(2d_compression "Compression example") diff --git a/model/solid_mechanics/contact.cc b/model/solid_mechanics/contact.cc index 91c94c28a..6db16a9d0 100644 --- a/model/solid_mechanics/contact.cc +++ b/model/solid_mechanics/contact.cc @@ -1,140 +1,143 @@ /** * @file contact.cc * @author David Kammer * @author Leonardo Snozzi * @author Nicolas Richart * @date Fri Oct 8 14:55:42 2010 * * @brief Common part of contact classes * * @section LICENSE * * \ * */ /* -------------------------------------------------------------------------- */ #include "contact.hh" #include "contact_search.hh" +#include "aka_common.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ Contact::Contact(const SolidMechanicsModel & model, ContactSearch & contact_search, const ContactID & id, const MemoryID & memory_id) : Memory(memory_id), id(id), model(model), contact_search(&contact_search) { AKANTU_DEBUG_IN(); AKANTU_DEBUG_OUT(); } Contact::~Contact() { AKANTU_DEBUG_IN(); delete contact_search; AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void Contact::initContact() { AKANTU_DEBUG_IN(); contact_search->initSearch(); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void Contact::checkAndUpdate() { AKANTU_DEBUG_IN(); std::vector::iterator it; for (it = master_surfaces.begin(); it != master_surfaces.end(); ++it) { if(contact_search->checkIfUpdateStructureNeeded(*it)) { contact_search->updateStructure(*it); } } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void Contact::updateContact() { AKANTU_DEBUG_IN(); std::vector::iterator it; for (it = master_surfaces.begin(); it != master_surfaces.end(); ++it) { contact_search->updateStructure(*it); } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void Contact::addMasterSurface(const Surface & master_surface) { AKANTU_DEBUG_IN(); AKANTU_DEBUG_ASSERT(std::find(master_surfaces.begin(), master_surfaces.end(), master_surface) == master_surfaces.end(), "Master surface already registered in the master surface list"); master_surfaces.push_back(master_surface); contact_search->addMasterSurface(master_surface); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void Contact::removeMasterSurface(const Surface & master_surface) { AKANTU_DEBUG_IN(); AKANTU_DEBUG_ASSERT(std::find(master_surfaces.begin(), master_surfaces.end(), master_surface) != master_surfaces.end(), "Master surface not registered in the master surface list"); std::remove(master_surfaces.begin(), master_surfaces.end(), master_surface); contact_search->removeMasterSurface(master_surface); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ Contact * Contact::newContact(const SolidMechanicsModel & model, const ContactType & contact_type, const ContactSearchType & contact_search_type, const ContactNeighborStructureType & contact_neighbor_structure_type, const ContactID & id) { AKANTU_DEBUG_IN(); std::stringstream sstr; sstr << id << ":contact_search"; ContactSearch * tmp_search = NULL; switch(contact_search_type) { case _cst_not_defined: // tmp_search = new ContactSearch(this, contact_neighbor_structure_type, sstr.str()); AKANTU_DEBUG_ERROR("Not a valid contact search type : " << contact_search_type); break; + // case _cst_2d_expli: { tmp_search = new ContactSearch2d(this, contact_neighbor_structure_type, sstr.str()); break; } } Contact * tmp_contact = NULL; switch(contact_search_type) { case _ct_not_defined: // tmp_contact = new Contact(model, tmp_search, id); AKANTU_DEBUG_ERROR("Not a valid contact type : " << contact_type); break; + // case _ct_2d_expli: { tmp_contact = new Contact2d(model, tmp_search, id); break; } } AKANTU_DEBUG_OUT(); return tmp_contact; } __END_AKANTU__ diff --git a/model/solid_mechanics/contact.hh b/model/solid_mechanics/contact.hh index 857951caa..f7a7cb351 100644 --- a/model/solid_mechanics/contact.hh +++ b/model/solid_mechanics/contact.hh @@ -1,128 +1,129 @@ + /** * @file contact.hh * @author Nicolas Richart * @author David Kammer * @author Leonardo Snozzi * @date Mon Sep 27 09:47:27 2010 * * @brief Interface for contact classes * * @section LICENSE * * \ * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_CONTACT_HH__ #define __AKANTU_CONTACT_HH__ /* -------------------------------------------------------------------------- */ #include "solid_mechanics_model.hh" #include "contact_search.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ // namespace akantu { // class ContactSearch; // } class Contact : public Memory { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ protected: Contact(const SolidMechanicsModel & model, ContactSearch & contact_search, const ContactID & id = "contact", const MemoryID & memory_id = 0); public: virtual ~Contact(); static Contact * newContact(const SolidMechanicsModel & model, const ContactType & contact_type, const ContactSearchType & contact_search_type, const ContactNeighborStructureType & contact_neighbor_structure_type, const ContactID & id = "contact"); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: /// update the internal structures virtual void initContact(); /// check if the neighbor structure need an update virtual void checkAndUpdate(); /// update the internal structures virtual void updateContact(); /// solve the contact virtual void solveContact() = 0; /// add a new master surface void addMasterSurface(const Surface & master_surface); /// remove a master surface void removeMasterSurface(const Surface & master_surface); /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: AKANTU_GET_MACRO(ID, id, const ContactID &); AKANTU_GET_MACRO(Model, model, const SolidMechanicsModel &); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: /// id of the contact class ContactID id; /// associated model const SolidMechanicsModel & model; /// contact search object ContactSearch * contact_search; /// list of master surfaces std::vector master_surfaces; /// offset of nodes per surface Vector surface_to_nodes_offset; /// list of surface nodes @warning Node can occur multiple time Vector surface_to_nodes; /// offset of surface elements per surface node ByElementTypeUInt node_to_elements_offset; - /// list of surface elements + /// list of surface elements id (elements can occur multiple times) ByElementTypeUInt node_to_elements; }; /* -------------------------------------------------------------------------- */ /* inline functions */ /* -------------------------------------------------------------------------- */ //#include "contact_inline_impl.cc" /// standard output stream operator // inline std::ostream & operator <<(std::ostream & stream, const Contact & _this) // { // _this.printself(stream); // return stream; //} __END_AKANTU__ #endif /* __AKANTU_CONTACT_HH__ */