diff --git a/src/model/solid_mechanics/solid_mechanics_model_cohesive/material_selector_cohesive.cc b/src/model/solid_mechanics/solid_mechanics_model_cohesive/material_selector_cohesive.cc index ba21f38cf..6d700f04f 100644 --- a/src/model/solid_mechanics/solid_mechanics_model_cohesive/material_selector_cohesive.cc +++ b/src/model/solid_mechanics/solid_mechanics_model_cohesive/material_selector_cohesive.cc @@ -1,166 +1,167 @@ /** * @file material_selector_cohesive.cc * * @author Mauro Corrado * @author Nicolas Richart * @author Marco Vocialta * * @date creation: Fri Dec 11 2015 * @date last modification: Mon Dec 18 2017 * * @brief Material selector for cohesive elements * * * Copyright (©) 2015-2018 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "material_selector_cohesive.hh" #include "solid_mechanics_model_cohesive.hh" /* -------------------------------------------------------------------------- */ namespace akantu { /* -------------------------------------------------------------------------- */ DefaultMaterialCohesiveSelector::DefaultMaterialCohesiveSelector( const SolidMechanicsModelCohesive & model) : facet_material(model.getFacetMaterial()), mesh(model.getMesh()) { // backward compatibility v3: to get the former behavior back when the user // creates its own selector this->fallback_selector = std::make_shared(model.getMaterialByElement()); } /* -------------------------------------------------------------------------- */ UInt DefaultMaterialCohesiveSelector::operator()(const Element & element) { if (Mesh::getKind(element.type) == _ek_cohesive) { try { const Array & cohesive_el_to_facet = mesh.getMeshFacets().getSubelementToElement(element.type, element.ghost_type); bool third_dimension = (mesh.getSpatialDimension() == 3); const Element & facet = cohesive_el_to_facet(element.element, UInt(third_dimension)); if (facet_material.exists(facet.type, facet.ghost_type)) { return facet_material(facet.type, facet.ghost_type)(facet.element); } return fallback_value; } catch (...) { return fallback_value; } } else if (Mesh::getSpatialDimension(element.type) == mesh.getSpatialDimension() - 1) { return facet_material(element.type, element.ghost_type)(element.element); } else { return MaterialSelector::operator()(element); } } /* -------------------------------------------------------------------------- */ MeshDataMaterialCohesiveSelector::MeshDataMaterialCohesiveSelector( const SolidMechanicsModelCohesive & model) : model(model), mesh_facets(model.getMeshFacets()), material_index(mesh_facets.getData("physical_names")) { third_dimension = (model.getSpatialDimension() == 3); // backward compatibility v3: to get the former behavior back when the user // creates its own selector this->fallback_selector = std::make_shared>("physical_names", model); } /* -------------------------------------------------------------------------- */ UInt MeshDataMaterialCohesiveSelector::operator()(const Element & element) { if (Mesh::getKind(element.type) == _ek_cohesive or - Mesh::getSpatialDimension(element.type) == mesh_facets.getSpatialDimension() - 1) { + Mesh::getSpatialDimension(element.type) == + mesh_facets.getSpatialDimension() - 1) { Element facet; if (Mesh::getKind(element.type) == _ek_cohesive) { - facet = mesh_facets.getSubelementToElement(element.type, - element.ghost_type)(element.element, - UInt(third_dimension)); + facet = + mesh_facets.getSubelementToElement(element.type, element.ghost_type)( + element.element, UInt(third_dimension)); } else { facet = element; } - + try { std::string material_name = this->material_index(facet); return this->model.getMaterialIndex(material_name); } catch (...) { return fallback_value; } } return MaterialSelector::operator()(element); } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ MaterialCohesiveRulesSelector::MaterialCohesiveRulesSelector( const SolidMechanicsModelCohesive & model, const MaterialCohesiveRules & rules, ID mesh_data_id) // what we have here is the name of model and also // the name of different materials : model(model), mesh_data_id(std::move(mesh_data_id)), mesh(model.getMesh()), mesh_facets(model.getMeshFacets()), spatial_dimension(model.getSpatialDimension()), rules(rules) { // cohesive fallback this->fallback_selector = std::make_shared(model); // non cohesive fallback this->fallback_selector->setFallback( std::make_shared>(mesh_data_id, model)); } /* -------------------------------------------------------------------------- */ UInt MaterialCohesiveRulesSelector::operator()(const Element & element) { if (mesh_facets.getSpatialDimension(element.type) == (spatial_dimension - 1)) { const std::vector & element_to_subelement = mesh_facets.getElementToSubelement(element.type, element.ghost_type)(element.element); // Array & facets_check = model.getFacetsCheck(); const Element & el1 = element_to_subelement[0]; const Element & el2 = element_to_subelement[1]; ID id1 = mesh.getData(mesh_data_id, el1.type, el1.ghost_type)(el1.element); ID id2 = id1; if (el2 != ElementNull) { id2 = mesh.getData(mesh_data_id, el2.type, el2.ghost_type)(el2.element); } auto rit = rules.find(std::make_pair(id1, id2)); if (rit == rules.end()) { rit = rules.find(std::make_pair(id2, id1)); } if (rit != rules.end()) { return model.getMaterialIndex(rit->second); } } return MaterialSelector::operator()(element); } } // namespace akantu diff --git a/src/model/solid_mechanics/solid_mechanics_model_inline_impl.hh b/src/model/solid_mechanics/solid_mechanics_model_inline_impl.hh index b51c65190..d1c2ad950 100644 --- a/src/model/solid_mechanics/solid_mechanics_model_inline_impl.hh +++ b/src/model/solid_mechanics/solid_mechanics_model_inline_impl.hh @@ -1,101 +1,106 @@ /** * @file solid_mechanics_model_inline_impl.hh * * @author Guillaume Anciaux * @author Daniel Pino Muñoz * @author Nicolas Richart * * @date creation: Wed Aug 04 2010 * @date last modification: Tue Dec 05 2017 * * @brief Implementation of the inline functions of the SolidMechanicsModel * class * * * Copyright (©) 2010-2018 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "aka_named_argument.hh" #include "material_selector.hh" #include "material_selector_tmpl.hh" #include "solid_mechanics_model.hh" /* -------------------------------------------------------------------------- */ #ifndef AKANTU_SOLID_MECHANICS_MODEL_INLINE_IMPL_HH_ #define AKANTU_SOLID_MECHANICS_MODEL_INLINE_IMPL_HH_ namespace akantu { /* -------------------------------------------------------------------------- */ inline decltype(auto) SolidMechanicsModel::getMaterials() { return make_dereference_adaptor(materials); } /* -------------------------------------------------------------------------- */ inline decltype(auto) SolidMechanicsModel::getMaterials() const { return make_dereference_adaptor(materials); } /* -------------------------------------------------------------------------- */ inline Material & SolidMechanicsModel::getMaterial(UInt mat_index) { AKANTU_DEBUG_ASSERT(mat_index < materials.size(), "The model " << id << " has no material no " << mat_index); - return *materials[mat_index]; + return *materials.at(mat_index); } /* -------------------------------------------------------------------------- */ inline const Material & SolidMechanicsModel::getMaterial(UInt mat_index) const { AKANTU_DEBUG_ASSERT(mat_index < materials.size(), "The model " << id << " has no material no " << mat_index); - return *materials[mat_index]; + return *materials.at(mat_index); } /* -------------------------------------------------------------------------- */ inline Material & SolidMechanicsModel::getMaterial(const std::string & name) { std::map::const_iterator it = materials_names_to_id.find(name); - AKANTU_DEBUG_ASSERT(it != materials_names_to_id.end(), - "The model " << id << " has no material named " << name); + if(it == materials_names_to_id.end()) { + AKANTU_SILENT_EXCEPTION("The model " << id << " has no material named " << name); + } + return *materials[it->second]; } /* -------------------------------------------------------------------------- */ inline UInt SolidMechanicsModel::getMaterialIndex(const std::string & name) const { auto it = materials_names_to_id.find(name); - AKANTU_DEBUG_ASSERT(it != materials_names_to_id.end(), - "The model " << id << " has no material named " << name); + if(it == materials_names_to_id.end()) { + AKANTU_SILENT_EXCEPTION("The model " << id << " has no material named " << name); + } + return it->second; } /* -------------------------------------------------------------------------- */ inline const Material & SolidMechanicsModel::getMaterial(const std::string & name) const { auto it = materials_names_to_id.find(name); - AKANTU_DEBUG_ASSERT(it != materials_names_to_id.end(), - "The model " << id << " has no material named " << name); + if(it == materials_names_to_id.end()) { + AKANTU_SILENT_EXCEPTION("The model " << id << " has no material named " << name); + } return *materials[it->second]; } /* -------------------------------------------------------------------------- */ } // namespace akantu #endif /* AKANTU_SOLID_MECHANICS_MODEL_INLINE_IMPL_HH_ */ diff --git a/test/test_synchronizer/test_communicator.cc b/test/test_synchronizer/test_communicator.cc index c8deb7a40..744f41803 100644 --- a/test/test_synchronizer/test_communicator.cc +++ b/test/test_synchronizer/test_communicator.cc @@ -1,137 +1,137 @@ /** * @file test_communicator.cc * * @author Nicolas Richart * * @date creation Thu Feb 21 2019 * * @brief A Documented file. * * * Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ /* -------------------------------------------------------------------------- */ #include #include #include /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ using namespace akantu; TEST(Communicator, Bcast) { auto r = 0xdeadbeef; auto & c = Communicator::getStaticCommunicator(); c.broadcast(r); EXPECT_EQ(r, 0xdeadbeef); } TEST(Communicator, ReceiveAny) { std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> dis(1, 10); std::vector reqs; auto & c = Communicator::getStaticCommunicator(); auto && rank = c.whoAmI(); auto && size = c.getNbProc(); - for (auto n : arange(100)) { + for (auto n [[gnu::unused]] : arange(100)) { AKANTU_DEBUG_INFO("ROUND " << n); auto tag = Tag::genTag(0, 1, 0); if (rank == 0) { std::vector sends(size - 1); for (auto & s : sends) { s = dis(gen); } c.broadcast(sends); AKANTU_DEBUG_INFO("Messages " << [&]() { std::string msgs; for (auto s : enumerate(sends)) { if (std::get<0>(s) != 0) msgs += ", "; msgs += std::to_string(std::get<0>(s) + 1) + ": " + std::to_string(std::get<1>(s)); } return msgs; }()); int nb_recvs = 0; for (auto && data : enumerate(sends)) { auto & send = std::get<1>(data); int p = std::get<0>(data) + 1; if (send > 5) { reqs.push_back( c.asyncSend(send, p, tag, CommunicationMode::_synchronous)); } if (p <= send) { ++nb_recvs; } } c.receiveAnyNumber(reqs, [&](auto && proc, auto && msg) { EXPECT_EQ(msg[0], sends[proc - 1] + 100 * proc); EXPECT_LE(proc, sends[proc - 1]); --nb_recvs; }, tag); EXPECT_EQ(nb_recvs, 0); } else { std::vector recv(size - 1); c.broadcast(recv); AKANTU_DEBUG_INFO("Messages " << [&]() { std::string msgs; for (auto s : enumerate(recv)) { if (std::get<0>(s) != 0) msgs += ", "; msgs += std::to_string(std::get<0>(s) + 1) + ": " + std::to_string(std::get<1>(s)); } return msgs; }()); auto send = recv[rank - 1] + 100 * rank; if (rank <= recv[rank - 1]) { reqs.push_back( c.asyncSend(send, 0, tag, CommunicationMode::_synchronous)); } bool has_recv = false; c.receiveAnyNumber(reqs, [&](auto && proc, auto && msg) { EXPECT_EQ(msg[0], recv[rank - 1]); EXPECT_EQ(proc, 0); has_recv = true; }, tag); bool should_recv = (recv[rank - 1] > 5); EXPECT_EQ(has_recv, should_recv); } reqs.clear(); } }