diff --git a/packages/core.cmake b/packages/core.cmake index 829bfd042..9d185997b 100644 --- a/packages/core.cmake +++ b/packages/core.cmake @@ -1,251 +1,252 @@ #=============================================================================== # @file core.cmake # # @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> # @author Nicolas Richart <nicolas.richart@epfl.ch> # # @date Mon Nov 21 18:19:15 2011 # # @brief package description for core # # @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(AKANTU_CORE ON CACHE INTERNAL "core package for Akantu" FORCE) set(AKANTU_CORE_FILES # source files common/aka_ball.cc 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/shape_lagrange.cc fem/shape_linked.cc fem/mesh.cc fem/fem.cc fem/mesh_data.cc fem/boundary.cc fem/sub_boundary.cc io/dumper/dumpable.hh io/mesh_io.cc io/model_io.cc io/mesh_io/mesh_io_msh.cc io/mesh_io/mesh_io_diana.cc model/model.cc model/solid_mechanics/solid_mechanics_model.cc model/solid_mechanics/solid_mechanics_model_mass.cc model/solid_mechanics/solid_mechanics_model_boundary.cc model/solid_mechanics/solid_mechanics_model_material.cc model/solid_mechanics/material.cc model/solid_mechanics/material_parameters.cc model/solid_mechanics/materials/material_elastic.cc mesh_utils/mesh_pbc.cc mesh_utils/mesh_partition.cc mesh_utils/mesh_partition/mesh_partition_mesh_data.cc mesh_utils/mesh_utils.cc solver/sparse_matrix.cc solver/solver.cc synchronizer/synchronizer_registry.cc synchronizer/synchronizer.cc synchronizer/distributed_synchronizer.cc synchronizer/pbc_synchronizer.cc synchronizer/data_accessor.cc synchronizer/static_communicator.cc synchronizer/dof_synchronizer.cc #header files io/mesh_io.hh io/model_io.hh io/mesh_io/mesh_io_msh.hh io/mesh_io/mesh_io_diana.hh mesh_utils/mesh_utils.hh mesh_utils/mesh_partition.hh mesh_utils/mesh_partition/mesh_partition_scotch.hh mesh_utils/mesh_partition/mesh_partition_mesh_data.hh solver/sparse_matrix.hh solver/solver.hh synchronizer/synchronizer.hh synchronizer/synchronizer_registry.hh synchronizer/static_communicator_dummy.hh synchronizer/static_communicator_inline_impl.hh synchronizer/distributed_synchronizer.hh synchronizer/distributed_synchronizer_tmpl.hh synchronizer/pbc_synchronizer.hh synchronizer/static_communicator.hh synchronizer/dof_synchronizer.hh synchronizer/real_static_communicator.hh synchronizer/data_accessor.hh synchronizer/communication_buffer.hh common/aka_fwd.hh common/aka_grid.hh common/aka_grid_tmpl.hh common/aka_types.hh common/aka_static_memory.hh common/aka_static_memory_tmpl.hh common/aka_memory.hh common/aka_math.hh common/aka_math_tmpl.hh common/aka_blas_lapack.hh common/aka_csr.hh common/aka_error.hh common/aka_common.hh common/aka_vector.hh common/aka_vector_tmpl.hh common/aka_circular_vector.hh common/aka_event_handler.hh common/aka_random_generator.hh common/aka_bounding_box.hh common/aka_ci_string.hh common/aka_plane.hh common/aka_polytope.hh common/aka_ball.hh common/aka_timer.hh common/aka_tree.hh common/aka_typelist.hh common/aka_visitor.hh common/aka_grid_dynamic.hh common/aka_safe_enum.hh fem/mesh.hh fem/fem.hh fem/by_element_type.hh fem/shape_functions.hh fem/shape_lagrange.hh fem/fem_template.hh fem/fem_template_tmpl.hh fem/integrator_gauss.hh fem/integrator.hh fem/element_class.hh fem/shape_linked.hh fem/geometrical_data_tmpl.hh fem/mesh_data.hh fem/boundary.hh fem/sub_boundary.hh model/model.hh model/boundary_condition.hh model/boundary_condition_functor.hh model/parser.hh model/parser_tmpl.hh model/structural_mechanics/structural_mechanics_model.hh model/integration_scheme/integration_scheme_2nd_order.hh model/integration_scheme/generalized_trapezoidal.hh model/integration_scheme/newmark-beta.hh model/integration_scheme/integration_scheme_1st_order.hh model/solid_mechanics/solid_mechanics_model.hh model/solid_mechanics/solid_mechanics_model_tmpl.hh model/solid_mechanics/material.hh model/solid_mechanics/material_parameters.hh model/solid_mechanics/material_parameters_tmpl.hh model/solid_mechanics/materials/material_elastic.hh #inline implementation files mesh_utils/mesh_utils_inline_impl.cc solver/sparse_matrix_inline_impl.cc synchronizer/dof_synchronizer_inline_impl.cc synchronizer/communication_buffer_inline_impl.cc common/aka_common_inline_impl.cc common/aka_memory_inline_impl.cc common/aka_static_memory_inline_impl.cc common/aka_circular_vector_inline_impl.cc fem/integrator_gauss_inline_impl.cc fem/element_classes/element_class_point_1_inline_impl.cc fem/element_classes/element_class_triangle_3_inline_impl.cc fem/element_classes/element_class_segment_2_inline_impl.cc fem/element_classes/element_class_quadrangle_4_inline_impl.cc fem/element_classes/element_class_quadrangle_8_inline_impl.cc fem/element_classes/element_class_hexahedron_8_inline_impl.cc fem/element_classes/element_class_triangle_6_inline_impl.cc fem/element_classes/element_class_tetrahedron_10_inline_impl.cc fem/element_classes/element_class_segment_3_inline_impl.cc fem/element_classes/element_class_tetrahedron_4_inline_impl.cc fem/shape_functions_inline_impl.cc fem/mesh_inline_impl.cc fem/boundary_inline_impl.cc fem/sub_boundary_inline_impl.cc fem/mesh_data_tmpl.hh fem/by_element_type_tmpl.hh fem/fem_inline_impl.cc fem/shape_linked_inline_impl.cc fem/shape_lagrange_inline_impl.cc model/model_inline_impl.cc model/boundary_condition_functor_inline_impl.cc model/integration_scheme/generalized_trapezoidal_inline_impl.cc model/integration_scheme/newmark-beta_inline_impl.cc model/solid_mechanics/solid_mechanics_model_inline_impl.cc model/solid_mechanics/materials/material_elastic_inline_impl.cc model/solid_mechanics/material_inline_impl.cc model/parser_inline_impl.cc model/boundary_condition_tmpl.hh fem/geometrical_element.cc fem/element_class_tmpl.hh fem/element_class.cc fem/integration_element.cc fem/interpolation_element.cc model/solid_mechanics/materials/material_elastic_orthotropic.cc model/solid_mechanics/materials/material_elastic_orthotropic.hh model/solid_mechanics/materials/material_elastic_orthotropic_inline_impl.cc ) set(AKANTU_CORE_DEB_DEPEND libboost-dev ) set(AKANTU_CORE_TESTS test_solid_mechanics_model_square test_vector test_vector_iterator test_matrix test_csr test_grid test_static_memory test_mesh_io_msh test_mesh_io_msh_physical_names test_mesh_data test_facet_element_mapping test_mesh_boundary test_facet_extraction_triangle_3 test_facet_extraction_tetrahedron_4 test_pbc_tweak test_purify_mesh test_local_material test_interpolate_stress test_weight + test_mesh_partitionate_mesh_data test_solid_mechanics_model_boundary_condition test_solid_mechanics_model_circle_2 test_solid_mechanics_model_bar_traction2d test_solid_mechanics_model_bar_traction2d_structured test_solid_mechanics_model_bar_traction2d_structured_pbc test_solid_mechanics_model_cube3d test_solid_mechanics_model_cube3d_tetra10 test_solid_mechanics_model_cube3d_pbc test_surface_extraction_triangle_3 test_surface_extraction_tetrahedron_4 test_material_damage_non_local ) find_program(READLINK_COMMAND readlink) find_program(ADDR2LINE_COMMAND addr2line) mark_as_advanced(READLINK_COMMAND) mark_as_advanced(ADDR2LINE_COMMAND) diff --git a/src/mesh_utils/mesh_partition/mesh_partition_mesh_data.hh b/src/mesh_utils/mesh_partition/mesh_partition_mesh_data.hh index f5bb306cc..c0944185a 100644 --- a/src/mesh_utils/mesh_partition/mesh_partition_mesh_data.hh +++ b/src/mesh_utils/mesh_partition/mesh_partition_mesh_data.hh @@ -1,94 +1,94 @@ /** * @file mesh_partition_mesh_data.hh * * @author Dana Christen <dana.christen@epfl.ch> * * @date Mon May 01 10:22:00 2013 (On Labor Day, such a shame!) * * @brief mesh partitioning based on data provided in the mesh * * @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_PARTITION_MESH_DATA_HH__ #define __AKANTU_MESH_PARTITION_MESH_DATA_HH__ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "mesh_partition.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ class MeshPartitionMeshData : public MeshPartition { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: MeshPartitionMeshData(const Mesh & mesh, UInt spatial_dimension, const MemoryID & memory_id = 0); MeshPartitionMeshData(const Mesh & mesh, const ByElementTypeArray<UInt> & mapping, UInt spatial_dimension, const MemoryID & memory_id = 0); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: - virtual void partitionate(UInt nb_part, + virtual void partitionate(UInt nb_part = 0, const EdgeLoadFunctor & edge_load_func = ConstEdgeLoadFunctor(), const Array<UInt> & pairs = Array<UInt>()); virtual void reorder(); void setPartitionMapping(const ByElementTypeArray<UInt> & mapping); void setPartitionMappingFromMeshData(const std::string & data_name); private: /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: const ByElementTypeArray<UInt> * partition_mapping; }; /* -------------------------------------------------------------------------- */ /* inline functions */ /* -------------------------------------------------------------------------- */ __END_AKANTU__ #endif /* __AKANTU_MESH_PARTITION_MESH_DATA_HH__ */ diff --git a/src/model/boundary_condition.hh b/src/model/boundary_condition.hh index c29638b27..9cffbf1ac 100644 --- a/src/model/boundary_condition.hh +++ b/src/model/boundary_condition.hh @@ -1,93 +1,95 @@ /** * @file boundary_condition.hh * * @author Dana Christen <dana.christen@gmail.com> * * @date Wed Mar 18 11:30:00 2013 * * @brief XXX * * @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_BOUNDARY_CONDITION_HH__ #define __AKANTU_BOUNDARY_CONDITION_HH__ #include "aka_common.hh" #include "boundary_condition_functor.hh" #include "mesh.hh" #include "fem.hh" #include "sub_boundary.hh" #include <iostream> /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ template <class ModelType> class BoundaryCondition { /* ------------------------------------------------------------------------ */ /* Typedefs */ /* ------------------------------------------------------------------------ */ private: /* ------------------------------------------------------------------------ */ /* Constructors / Destructors / Initializers */ /* ------------------------------------------------------------------------ */ public: void initBC(ModelType & ptr, Array<Real> & primal, Array<Real> & dual); /* ------------------------------------------------------------------------ */ /* Methods and accessors */ /* ------------------------------------------------------------------------ */ public: //inline void initBoundaryCondition(); + template<typename FunctorType> + inline void applyBC(const FunctorType & func); template<class FunctorType> inline void applyBC(const FunctorType & func, const std::string & boundary_name); template<class FunctorType> inline void applyBC(const FunctorType & func, const SubBoundary & boundary_ref); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: template<class FunctorType, BC::Functor::Type type = FunctorType::type> struct TemplateFunctionWrapper; ModelType * model; Array<Real> * primal; Array<Real> * dual; }; #include "boundary_condition_tmpl.hh" __END_AKANTU__ #endif /* __AKANTU_BOUNDARY_CONDITION_HH__ */ diff --git a/src/model/boundary_condition_tmpl.hh b/src/model/boundary_condition_tmpl.hh index e8cb27f49..c93078b1d 100644 --- a/src/model/boundary_condition_tmpl.hh +++ b/src/model/boundary_condition_tmpl.hh @@ -1,169 +1,179 @@ /** * @file boundary_condition_inline_impl.cc * * @author Dana Christen <dana.christen@gmail.com> * * @date Wed Mar 18 11:30:00 2013 * * @brief XXX * * @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/>. * */ /* -------------------------------------------------------------------------- */ template<typename ModelType> void BoundaryCondition<ModelType>::initBC(ModelType & ref, Array<Real> & primal_, Array<Real> & dual_) { model = &ref; primal = &primal_; dual = &dual_; model->initFEMBoundary(); } /* -------------------------------------------------------------------------- */ /* Partial specialization for DIRICHLET functors */ template<typename ModelType> template<typename FunctorType> struct BoundaryCondition<ModelType>::TemplateFunctionWrapper<FunctorType, BC::Functor::_dirichlet> { static inline void applyBC(const FunctorType & func, const SubBoundary & boundary_ref, BoundaryCondition<ModelType> & bc_instance) { ModelType & model = *bc_instance.model; const Array<Real> & coords = model.mesh.getNodes(); UInt dim = model.mesh.getSpatialDimension(); Array<Real> & primal = *bc_instance.primal; Array<bool> & boundary_flags = model.getBoundary(); Array<Real>::iterator<Vector<Real> > primal_iter = primal.begin(primal.getNbComponent()); Array<Real>::const_iterator<Vector<Real> > coords_iter = coords.begin(dim); Array<bool>::iterator<Vector<bool> > flags_iter = boundary_flags.begin(boundary_flags.getNbComponent()); for(SubBoundary::nodes_const_iterator nodes_it(boundary_ref.nodes_begin()); nodes_it!= boundary_ref.nodes_end(); ++nodes_it) { UInt n = *nodes_it; func(n, flags_iter[n], primal_iter[n], coords_iter[n]); } } }; /* -------------------------------------------------------------------------- */ /* Partial specialization for NEUMANN functors */ template<typename ModelType> template<typename FunctorType> struct BoundaryCondition<ModelType>::TemplateFunctionWrapper<FunctorType, BC::Functor::_neumann> { static inline void applyBC(const FunctorType & func, const SubBoundary & boundary_ref, BoundaryCondition<ModelType> & bc_instance) { ModelType & model = *bc_instance.model; const Array<Real> & nodes_coords = model.getMesh().getNodes(); UInt dim = model.getSpatialDimension(); Array<Real> & dual = *bc_instance.dual; const FEM & fem_boundary = model.getFEMBoundary(); UInt nb_degree_of_freedom = dual.getNbComponent(); Mesh::type_iterator type_it = model.mesh.firstType(dim-1); Mesh::type_iterator type_end = model.mesh.lastType(dim-1); // Loop over the boundary element types for(; type_it != type_end; ++type_it) { const Array<UInt> & element_ids = boundary_ref.getElements(*type_it); Array<UInt>::const_iterator<UInt> elem_iter = element_ids.begin(); Array<UInt>::const_iterator<UInt> elem_iter_end = element_ids.end(); UInt nb_quad_points = model.getFEMBoundary().getNbQuadraturePoints(*type_it); UInt nb_elements = element_ids.getSize(); UInt nb_nodes_per_element = model.getMesh().getNbNodesPerElement(*type_it); Array<Real> * dual_before_integ = new Array<Real>(nb_elements * nb_quad_points, nb_degree_of_freedom); Array<Real> * quad_coords = new Array<Real>(nb_elements * nb_quad_points, dim); Array<Real>::iterator<Vector<Real> > dual_iter = dual_before_integ->begin(nb_degree_of_freedom); const Array<Real> & normals_on_quad = fem_boundary.getNormalsOnQuadPoints(*type_it); fem_boundary.interpolateOnQuadraturePoints(nodes_coords, *quad_coords, dim, *type_it, _not_ghost, element_ids); Array<Real>::const_iterator< Vector<Real> > normals_iter = normals_on_quad.begin(dim); Array<Real>::const_iterator< Vector<Real> > quad_coords_iter = quad_coords->begin(dim); QuadraturePoint quad_point; quad_point.type = *type_it; // Loop over the elements in the SubBoundary for(; elem_iter != elem_iter_end; ++elem_iter) { UInt n = *elem_iter; quad_point.element = n; UInt offset = (n*nb_quad_points); for(UInt j(0); j<nb_quad_points; ++j) { quad_point.num_point = j; func(quad_point, *dual_iter, *quad_coords_iter, normals_iter[offset]); ++dual_iter; ++quad_coords_iter; ++offset; } } delete quad_coords; Array<Real>::iterator<Matrix<Real> > dual_iter_mat = dual_before_integ->begin(nb_degree_of_freedom,1); elem_iter = element_ids.begin(); Array<Real>::const_iterator<Matrix<Real> > shapes_iter_begin = fem_boundary.getShapes(*type_it).begin(1, nb_nodes_per_element); Array<Real> * dual_by_shapes = new Array<Real>(nb_elements*nb_quad_points, nb_degree_of_freedom*nb_nodes_per_element); Array<Real>::iterator<Matrix<Real> > dual_by_shapes_iter = dual_by_shapes->begin(nb_degree_of_freedom, nb_nodes_per_element); for(; elem_iter != elem_iter_end; ++elem_iter) { Array<Real>::const_iterator<Matrix<Real> > shapes_iter = shapes_iter_begin + *elem_iter*nb_quad_points; for(UInt j(0); j<nb_quad_points; ++j, ++dual_iter_mat, ++dual_by_shapes_iter, ++shapes_iter) { dual_by_shapes_iter->mul<false, false>(*dual_iter_mat, *shapes_iter); } } delete dual_before_integ; Array<Real> * dual_by_shapes_integ = new Array<Real>(nb_elements, nb_degree_of_freedom*nb_nodes_per_element); fem_boundary.integrate(*dual_by_shapes, *dual_by_shapes_integ, nb_degree_of_freedom*nb_nodes_per_element, *type_it, _not_ghost, element_ids); delete dual_by_shapes; // assemble the result into force vector fem_boundary.assembleArray(*dual_by_shapes_integ, dual, model.getDOFSynchronizer().getLocalDOFEquationNumbers(), nb_degree_of_freedom, *type_it, _not_ghost, element_ids); delete dual_by_shapes_integ; } } }; +/* -------------------------------------------------------------------------- */ +template<typename ModelType> +template<typename FunctorType> +inline void BoundaryCondition<ModelType>::applyBC(const FunctorType & func) { + Boundary::const_iterator bit = model->getMesh().getBoundary().begin(); + Boundary::const_iterator bend = model->getMesh().getBoundary().end(); + for(; bit != bend; ++bit) { + TemplateFunctionWrapper<FunctorType>::applyBC(func, *bit, *this); + } +} /* -------------------------------------------------------------------------- */ template<typename ModelType> template<typename FunctorType> inline void BoundaryCondition<ModelType>::applyBC(const FunctorType & func, const std::string & boundary_name) { const SubBoundary & boundary_ref = model->getMesh().getSubBoundary(boundary_name); TemplateFunctionWrapper<FunctorType>::applyBC(func, boundary_ref, *this); } /* -------------------------------------------------------------------------- */ template<typename ModelType> template<typename FunctorType> inline void BoundaryCondition<ModelType>::applyBC(const FunctorType & func, const SubBoundary & boundary_ref) { TemplateFunctionWrapper<FunctorType>::applyBC(func, boundary_ref, *this); } diff --git a/test/test_fem/test_facet_element_mapping.cc b/test/test_fem/test_facet_element_mapping.cc index 037672909..0e4b582a8 100644 --- a/test/test_fem/test_facet_element_mapping.cc +++ b/test/test_fem/test_facet_element_mapping.cc @@ -1,120 +1,119 @@ /** * @file test_mesh_data.hh * * @author Dana Christen <dana.christen@gmail.com> * * @date Thu Feb 27 15:00:00 2013 * * @brief Test of the MeshData 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 "mesh.hh" #include "mesh_utils.hh" #include "aka_common.hh" #include "aka_error.hh" /* -------------------------------------------------------------------------- */ #include <iostream> #include <string> /* -------------------------------------------------------------------------- */ using namespace akantu; using namespace std; int main(int argc, char *argv[]) { // Testing the subelement-to-element mappings UInt spatial_dimension(3); akantu::initialize(argc, argv); Mesh mesh(spatial_dimension, "my_mesh"); mesh.read("./cube_physical_names.msh"); typedef Array< std::vector<Element> > ElemToSubelemMapping; typedef Array<Element> SubelemToElemMapping; std::cout << "ELEMENT-SUBELEMENT MAPPING:" << std::endl; for (ghost_type_t::iterator git = ghost_type_t::begin(); git != ghost_type_t::end(); ++git) { Mesh::type_iterator tit = mesh.firstType(spatial_dimension, *git); Mesh::type_iterator tend = mesh.lastType(spatial_dimension, *git); std::cout << " " << "Ghost type: " << *git << std::endl; for (;tit != tend; ++tit) { const SubelemToElemMapping & subelement_to_element = mesh.getSubelementToElement(*tit, *git); std::cout << " " << " " << "Element type: " << *tit << std::endl; std::cout << " " << " " << " " << "subelement_to_element:" << std::endl; subelement_to_element.printself(std::cout, 8); for(UInt i(0); i < subelement_to_element.getSize(); ++i) { std::cout << " "; for(UInt j(0); j < mesh.getNbFacetsPerElement(*tit); ++j) { if(subelement_to_element(i, j) != ElementNull) { subelement_to_element(i, j).printself(std::cout); std::cout << ", "; } else { std::cout << "ElementNull" << ", "; } } std::cout << "for element " << i << std::endl; } } - debug::setDebugLevel(dblInfo); tit = mesh.firstType(spatial_dimension -1, *git); tend = mesh.lastType(spatial_dimension -1 , *git); for (;tit != tend; ++tit) { const ElemToSubelemMapping & element_to_subelement = mesh.getElementToSubelement(*tit, *git); std::cout << " " << " " << "Element type: " << *tit << std::endl; std::cout << " " << " " << " " << "element_to_subelement:" << std::endl; element_to_subelement.printself(std::cout, 8); for(UInt i(0); i < element_to_subelement.getSize(); ++i) { const std::vector<Element> & vec = element_to_subelement(i); std::cout << " " ; std::cout << "item " << i << ": [ "; if(vec.size() > 0) { for(UInt j(0); j < vec.size(); ++j) { if(vec[j] != ElementNull) { std::cout << vec[j] << ", "; } else { std::cout << "ElementNull" << ", "; } } } else { std::cout << "empty, " ; } std::cout << "]" << ", " << std::endl; } std::cout << std::endl; } } return 0; } diff --git a/test/test_mesh_utils/test_mesh_partitionate/CMakeLists.txt b/test/test_mesh_utils/test_mesh_partitionate/CMakeLists.txt index e841c7f31..5faf1fc19 100644 --- a/test/test_mesh_utils/test_mesh_partitionate/CMakeLists.txt +++ b/test/test_mesh_utils/test_mesh_partitionate/CMakeLists.txt @@ -1,45 +1,54 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> # # @date Fri Sep 03 15:56:15 2010 # # @brief configuration for mesh partitioner tests # # @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 # #=============================================================================== add_mesh(test_mesh_partitionate_mesh triangle.geo 2 2) +add_mesh(test_mesh_partitionate_mesh_data_mesh + quad.geo 2 1) + register_test(test_mesh_partitionate_scotch SOURCES test_mesh_partitionate_scotch.cc DEPENDENCIES test_mesh_partitionate_mesh DIRECTORIES_TO_CREATE paraview ) register_test(test_mesh_partitionate_scotch_advanced SOURCES test_mesh_partitionate_scotch_advanced.cc FILES_TO_COPY squares_L.msh squares_H.msh DIRECTORIES_TO_CREATE paraview) + +register_test(test_mesh_partitionate_mesh_data + SOURCES test_mesh_partitionate_mesh_data.cc + DEPENDENCIES test_mesh_partitionate_mesh_data_mesh + DIRECTORIES_TO_CREATE paraview) + diff --git a/test/test_mesh_utils/test_mesh_partitionate/triangle.geo b/test/test_mesh_utils/test_mesh_partitionate/quad.geo similarity index 88% copy from test/test_mesh_utils/test_mesh_partitionate/triangle.geo copy to test/test_mesh_utils/test_mesh_partitionate/quad.geo index 71ba2c022..03aacaa5b 100644 --- a/test/test_mesh_utils/test_mesh_partitionate/triangle.geo +++ b/test/test_mesh_utils/test_mesh_partitionate/quad.geo @@ -1,26 +1,29 @@ // Mesh size -h = 0.05; // Top cube +h = .05; // Top cube // Dimensions of top cube Lx = 1; Ly = 1; // Base Cube Point(101) = { 0.0, 0.0, 0.0, h}; // Bottom Face Point(102) = { Lx, 0.0, 0.0, h}; // Bottom Face Point(103) = { Lx, Ly, 0.0, h}; // Bottom Face Point(104) = { 0.0, Ly, 0.0, h}; // Bottom Face // Base Cube Line(101) = {101,102}; // Bottom Face Line(102) = {102,103}; // Bottom Face Line(103) = {103,104}; // Bottom Face Line(104) = {104,101}; // Bottom Face // Base Cube Line Loop(101) = {101:104}; // Base Cube Plane Surface(101) = {101}; Physical Surface(6) = {101}; + +Transfinite Surface "*"; +Recombine Surface "*"; diff --git a/test/test_mesh_utils/test_mesh_partitionate/test_mesh_partitionate_mesh_data.cc b/test/test_mesh_utils/test_mesh_partitionate/test_mesh_partitionate_mesh_data.cc new file mode 100644 index 000000000..b0cbe2786 --- /dev/null +++ b/test/test_mesh_utils/test_mesh_partitionate/test_mesh_partitionate_mesh_data.cc @@ -0,0 +1,104 @@ +/** + * @file test_mesh_partitionate_mesh_data.cc + * + * @author Dana Christen <dana.christen@epfl.ch> + * + * @date Tue May 07 17:16:12 2013 + * + * @brief test of manual partitioner + * + * @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 <cmath> +/* -------------------------------------------------------------------------- */ +#include "aka_common.hh" +#include "mesh.hh" +#include "mesh_partition_mesh_data.hh" +/* -------------------------------------------------------------------------- */ +#ifdef AKANTU_USE_IOHELPER +# include "dumper_paraview.hh" +#endif //AKANTU_USE_IOHELPER + +using namespace akantu; +/* -------------------------------------------------------------------------- */ +/* Main */ +/* -------------------------------------------------------------------------- */ +int main(int argc, char *argv[]) +{ + initialize(argc, argv); + + UInt dim = 2; + UInt nb_partitions = 8; + akantu::Mesh mesh(dim); + mesh.read("quad.msh"); + ByElementTypeArray<UInt> partition; + UInt nb_component = 1; + GhostType gt = _not_ghost; + Mesh::type_iterator tit = mesh.firstType(dim, gt); + Mesh::type_iterator tend = mesh.lastType(dim, gt); + + for(; tit != tend; ++tit) { + UInt nb_element = mesh.getNbElement(*tit, gt); + partition.alloc(nb_element, nb_component, *tit, gt); + Array<UInt> & type_partition_reference = partition(*tit, gt); + for(UInt i(0); i < nb_element; ++i) { + Real barycenter[2]; + mesh.getBarycenter(i, *tit, barycenter, gt); + Real real_proc = barycenter[0] * nb_partitions; + if(real_proc-round(real_proc) < 10*std::numeric_limits<Real>::min()) { + type_partition_reference(i) = round(real_proc); + } else { + std::cout << "*"; + type_partition_reference(i) = floor(real_proc); + } + std::cout << "Assigned proc " << type_partition_reference(i) << " to elem " << i << " (type " << *tit << ", baryxcenter x-coordinate " << barycenter[0] << ")" << std::endl; + } + } + + akantu::MeshPartitionMeshData * partitioner = new akantu::MeshPartitionMeshData(mesh, dim); + partitioner->setPartitionMapping(partition); + partitioner->partitionate(); + + tit = mesh.firstType(dim, gt); + for(; tit != tend; ++tit) { + UInt nb_element = mesh.getNbElement(*tit, gt); + const Array<UInt> & type_partition_reference = partition(*tit, gt); + const Array<UInt> & type_partition = partitioner->getPartitions()(*tit, gt); + for(UInt i(0); i < nb_element; ++i) { + AKANTU_DEBUG_ASSERT(type_partition(i) == type_partition_reference(i), "Incorrect partitioning"); + } + } + +#ifdef AKANTU_USE_IOHELPER + DumperParaview dumper("test-mesh-data-partition"); + DumperIOHelper::Field * field = new DumperIOHelper::ElementalField<UInt>(partitioner->getPartitions(), dim); + dumper.registerMesh(mesh, dim); + dumper.registerField("partitions", field); + dumper.dump(); +#endif //AKANTU_USE_IOHELPER + + delete partitioner; + + finalize(); + + return EXIT_SUCCESS; +} diff --git a/test/test_mesh_utils/test_mesh_partitionate/triangle.geo b/test/test_mesh_utils/test_mesh_partitionate/triangle.geo index 71ba2c022..4aa0b9222 100644 --- a/test/test_mesh_utils/test_mesh_partitionate/triangle.geo +++ b/test/test_mesh_utils/test_mesh_partitionate/triangle.geo @@ -1,26 +1,27 @@ // Mesh size -h = 0.05; // Top cube +h = .1; // Top cube // Dimensions of top cube Lx = 1; Ly = 1; // Base Cube Point(101) = { 0.0, 0.0, 0.0, h}; // Bottom Face Point(102) = { Lx, 0.0, 0.0, h}; // Bottom Face Point(103) = { Lx, Ly, 0.0, h}; // Bottom Face Point(104) = { 0.0, Ly, 0.0, h}; // Bottom Face // Base Cube Line(101) = {101,102}; // Bottom Face Line(102) = {102,103}; // Bottom Face Line(103) = {103,104}; // Bottom Face Line(104) = {104,101}; // Bottom Face // Base Cube Line Loop(101) = {101:104}; // Base Cube Plane Surface(101) = {101}; Physical Surface(6) = {101}; +