diff --git a/extra_packages/traction-at-split-node-contact/test/test_ntn_model/data/material_ntn_model.dat b/extra_packages/traction-at-split-node-contact/test/test_ntn_model/data/material_ntn_model.dat index 30e3f810e..5876c7daa 100644 --- a/extra_packages/traction-at-split-node-contact/test/test_ntn_model/data/material_ntn_model.dat +++ b/extra_packages/traction-at-split-node-contact/test/test_ntn_model/data/material_ntn_model.dat @@ -1,6 +1,6 @@ material elastic [ - name = steel - rho = 7800 # density - E = 2.1e11 # young's modulus + name = normalized + rho = 1 # density + E = 1 # young's modulus nu = 0.0 # poisson's ratio ] diff --git a/extra_packages/traction-at-split-node-contact/test/test_ntn_model/test_ntn_basics.cc b/extra_packages/traction-at-split-node-contact/test/test_ntn_model/test_ntn_basics.cc index c4dd2e3ee..137475ad3 100644 --- a/extra_packages/traction-at-split-node-contact/test/test_ntn_model/test_ntn_basics.cc +++ b/extra_packages/traction-at-split-node-contact/test/test_ntn_model/test_ntn_basics.cc @@ -1,106 +1,116 @@ /** * Copyright (©) 2018-2023 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * This file is part of Akantu * * 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 "test_ntn_fixture.hh" /* -------------------------------------------------------------------------- */ #include <gtest/gtest.h> namespace akantu{ TEST_F(TestNTNFixture,TestInterfacePairing) { - std::string filename = "material_ntn_model.dat"; - - this->initSolidMechanicsModel(filename); - this->initContactModel(); auto spatial_dimension = this->mesh->getSpatialDimension(); auto & slaves = this->contact->getSlaves().getArray(); auto & masters = this->contact->getMasters().getArray(); const auto & position = this->mesh->getNodes(); for (auto && [s,m] : zip(slaves,masters)){ for (Int i = 0; i < spatial_dimension;i++){ auto distance = position(s,i)-position(m,i); EXPECT_NEAR(0, distance, 1e-10); } } }; TEST_F(TestNTNFixture,TestLumpedBoundary) { // Test computation of lumped boundary. // It computes the "surface of influence" associated // to an interfacial node - std::string filename = "material_ntn_model.dat"; - - this->initSolidMechanicsModel(filename); - this->initContactModel(); - const auto & l_boundary_slaves = this->ntn_contact->getLumpedBoundarySlaves(); const auto & l_boundary_masters = this->ntn_contact->getLumpedBoundaryMasters(); auto & slaves = this->contact->getSlaves().getArray(); auto & masters = this->contact->getMasters().getArray(); const auto & position = this->mesh->getNodes(); - const Vector<Real> lowerBounds = this->mesh->getLowerBounds(); const Vector<Real> upperBounds = this->mesh->getUpperBounds(); Real left = lowerBounds(0); Real right = upperBounds(0); Real system_length = right - left; Int nb_contact_nodes = this->ntn_contact->getNbContactNodes(); Real l_b_side = system_length / (nb_contact_nodes + 1); Real l_b_bulk = system_length / (nb_contact_nodes + 1) * 2; Real tol = 1e-11; for (Int n = 0; n < nb_contact_nodes; ++n){ if((std::abs(position(slaves(n),_x)-left)<tol)or(std::abs(position(slaves(n),_x)-right)<tol)) EXPECT_NEAR(l_b_side,l_boundary_slaves(n),1e-11); else EXPECT_NEAR(l_b_bulk,l_boundary_slaves(n),1e-11); if((std::abs(position(masters(n),_x)-left)<tol)or(std::abs(position(masters(n),_x)-right)<tol)) EXPECT_NEAR(l_b_side,l_boundary_masters(n),1e-11); else EXPECT_NEAR(l_b_bulk,l_boundary_masters(n),1e-11); } }; TEST_F(TestNTNFixture,TestImpedance) { - std::string filename = "material_ntn_model.dat"; + + Real time_step_factor = 0.1; + this->initDynamics(time_step_factor); + + // Expected impedance is 1/ [dt/2 *(lumped_boundary[slaves]/mass[slaves] + lumped_boundary[masters]/mass[masters])] + auto & impedance = this->ntn_contact->getImpedance(); + Real delta_t = this->model->getTimeStep(); - this->initSolidMechanicsModel(filename); - this->initContactModel(); + const Vector<Real> lowerBounds = this->mesh->getLowerBounds(); + const Vector<Real> upperBounds = this->mesh->getUpperBounds(); + Real bottom = lowerBounds(1); + Real top = upperBounds(1); + Real system_height = top - bottom; + + Real density = 1; + + // Expected impedance can be reduced in this case to + // density * system_height / (4*dt) + Real imp_ref = density*system_height / (4*delta_t) ; + + for(auto && imp: + impedance){ + EXPECT_NEAR(imp,imp_ref,1e-11); + + } }; - - + } diff --git a/extra_packages/traction-at-split-node-contact/test/test_ntn_model/test_ntn_fixture.hh b/extra_packages/traction-at-split-node-contact/test/test_ntn_model/test_ntn_fixture.hh index 034f0ff2c..bdc85ec7b 100644 --- a/extra_packages/traction-at-split-node-contact/test/test_ntn_model/test_ntn_fixture.hh +++ b/extra_packages/traction-at-split-node-contact/test/test_ntn_model/test_ntn_fixture.hh @@ -1,97 +1,108 @@ /** * Copyright (©) 2018-2023 EPFL (Ecole Polytechnique Fédérale de Lausanne) * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * This file is part of Akantu * * 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_utils.hh" #include "solid_mechanics_model.hh" #include "ntn_contact.hh" #include "ntn_base_contact.hh" /* -------------------------------------------------------------------------- */ #include <gtest/gtest.h> #ifndef AKANTU_NTN_TEST_FIXTURE_HH_ #define AKANTU_NTN_TEST_FIXTURE_HH_ // #define DEBUG_TEST namespace akantu{ class TestNTNFixture : public ::testing::Test{ public: virtual void SetUp() { UInt dim = 2; mesh = std::make_unique<Mesh>(dim); mesh->read("ntn_test_2d.msh"); model = std::make_unique<SolidMechanicsModel>(*mesh); ntn_contact = new NTNContact(*model); - + + std::string filename = "material_ntn_model.dat"; + + this->initSolidMechanicsModel(filename); + this->initContactModel(); + } virtual void TearDown(){ model.reset(nullptr); mesh.reset(nullptr); delete ntn_contact; } virtual void initSolidMechanicsModel(const std::string & material_file){ getStaticParser().parse(material_file); // Create model model->initFull(SolidMechanicsModelOptions(_explicit_lumped_mass)); model->assembleInternalForces(); for (Int i = 0; i < model->getNbMaterials(); ++i) { model->getMaterial(i).setToSteadyState(_not_ghost); model->getMaterial(i).setToSteadyState(_ghost); } model->assembleInternalForces(); model->assembleMassLumped(); model->assembleInternalForces(); } virtual void initContactModel(){ - // Create the contact and node to node interface + // Create the contact and node to node interface contact = NULL; ntn_contact->addSurfacePair("slider_bottom","base_top",1); contact = ntn_contact; contact->updateNormals(); contact->updateLumpedBoundary(); - contact->updateImpedance(); } + virtual void initDynamics(Real time_step_factor){ + // Set the time step and compute the impedance + Real stable_time_step = model->getStableTimeStep(); + Real time_step = stable_time_step * time_step_factor; + model->setTimeStep(time_step); + contact->updateImpedance(); + } protected: std::unique_ptr<Mesh> mesh; std::unique_ptr<SolidMechanicsModel> model; NTNContact *contact; NTNContact *ntn_contact; }; // namespace akantu } #endif /* AKANTU_NTN_TEST_FIXTURE_HH_ */