diff --git a/test/test_model/patch_tests/CMakeLists.txt b/test/test_model/patch_tests/CMakeLists.txt index bf01bd82c..75533ca82 100644 --- a/test/test_model/patch_tests/CMakeLists.txt +++ b/test/test_model/patch_tests/CMakeLists.txt @@ -1,126 +1,136 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux # @author David Simon Kammer # @author Nicolas Richart # # @date creation: Fri Oct 22 2010 # @date last modification: Thu Feb 08 2018 # # @brief configuration for patch tests # # @section LICENSE # # 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 . # # @section DESCRIPTION # #=============================================================================== add_subdirectory(data) register_gtest_sources(SOURCES patch_test_linear_elastic_explicit.cc PACKAGE solid_mechanics FILES_TO_COPY data/material_check_stress_plane_strain.dat - data/material_check_stress_plane_stress.dat) + data/material_check_stress_plane_stress.dat + data/material_check_stress_plane_strain_finite_deformation.dat + data/material_check_stress_plane_stress_finite_deformation.dat) register_gtest_sources(SOURCES patch_test_linear_elastic_implicit.cc PACKAGE solid_mechanics implicit FILES_TO_COPY data/material_check_stress_plane_strain.dat data/material_check_stress_plane_stress.dat data/material_check_stress_plane_strain_finite_deformation.dat data/material_check_stress_plane_stress_finite_deformation.dat) -register_gtest_sources(SOURCES patch_test_linear_anisotropic.cc +register_gtest_sources(SOURCES patch_test_linear_anisotropic_explicit.cc PACKAGE solid_mechanics lapack FILES_TO_COPY data/material_anisotropic_1.dat data/material_anisotropic_2.dat data/material_anisotropic_3.dat ) +register_gtest_sources(SOURCES patch_test_linear_anisotropic_implicit.cc + PACKAGE solid_mechanics lapack implicit + FILES_TO_COPY + data/material_anisotropic_1.dat + data/material_anisotropic_2.dat + data/material_anisotropic_3.dat + ) + register_gtest_sources(SOURCES test_lumped_mass.cc PACKAGE solid_mechanics FILES_TO_COPY data/material_lumped.dat) register_gtest_sources( SOURCES patch_test_linear_heat_transfer_explicit.cc FILES_TO_COPY data/heat_transfer_input.dat PACKAGE heat_transfer) register_gtest_sources( SOURCES patch_test_linear_heat_transfer_static.cc FILES_TO_COPY data/heat_transfer_input.dat PACKAGE heat_transfer implicit) register_gtest_sources( SOURCES patch_test_linear_heat_transfer_implicit.cc FILES_TO_COPY data/heat_transfer_input.dat PACKAGE heat_transfer implicit ) register_gtest_test(patch_test_linear FILES_TO_COPY ${PATCH_TEST_MESHES}) register_test(test_linear_elastic_explicit_python SCRIPT test_patch_linear_elastic_explicit.py PYTHON PACKAGE python_interface FILES_TO_COPY patch_test_linear_fixture.py FILES_TO_COPY patch_test_linear_solid_mechanics_fixture.py FILES_TO_COPY ${PATCH_TEST_MESHES}) register_test(test_linear_elastic_static_python SCRIPT test_patch_linear_elastic_static.py PYTHON PACKAGE python_interface implicit FILES_TO_COPY patch_test_linear_fixture.py FILES_TO_COPY patch_test_linear_solid_mechanics_fixture.py) register_test(test_linear_anisotropic_explicit_python SCRIPT test_patch_linear_anisotropic_explicit.py PYTHON UNSTABLE PACKAGE python_interface lapack FILES_TO_COPY patch_test_linear_fixture.py FILES_TO_COPY patch_test_linear_solid_mechanics_fixture.py FILES_TO_COPY data/material_anisotropic_3.dat) register_test(patch_test_linear_heat_transfer_explicit_python SCRIPT test_patch_linear_heat_transfer_explicit.py PYTHON PACKAGE python_interface heat_transfer FILES_TO_COPY patch_test_linear_fixture.py FILES_TO_COPY patch_test_linear_heat_transfer_fixture.py FILES_TO_COPY data/heat_transfer_input.dat) register_test(patch_test_linear_heat_transfer_static_python SCRIPT test_patch_linear_heat_transfer_static.py PYTHON PACKAGE python_interface heat_transfer implicit FILES_TO_COPY patch_test_linear_fixture.py FILES_TO_COPY patch_test_linear_heat_transfer_fixture.py FILES_TO_COPY data/heat_transfer_input.dat) register_test(patch_test_linear_heat_transfer_implicit_python SCRIPT test_patch_linear_heat_transfer_implicit.py PYTHON PACKAGE python_interface heat_transfer implicit FILES_TO_COPY patch_test_linear_fixture.py FILES_TO_COPY patch_test_linear_heat_transfer_fixture.py FILES_TO_COPY data/heat_transfer_input.dat) diff --git a/test/test_model/patch_tests/patch_test_linear_anisotropic.cc b/test/test_model/patch_tests/patch_test_linear_anisotropic_explicit.cc similarity index 60% copy from test/test_model/patch_tests/patch_test_linear_anisotropic.cc copy to test/test_model/patch_tests/patch_test_linear_anisotropic_explicit.cc index f64b66df7..6cf532a2a 100644 --- a/test/test_model/patch_tests/patch_test_linear_anisotropic.cc +++ b/test/test_model/patch_tests/patch_test_linear_anisotropic_explicit.cc @@ -1,223 +1,136 @@ /** * @file patch_test_linear_anisotropic_explicit.cc * * @author Guillaume Anciaux * @author Till Junge * @author David Simon Kammer * @author Nicolas Richart * @author Cyprien Wolff * * @date creation: Tue Dec 05 2017 * @date last modification: Tue Feb 13 2018 * * @brief patch test for elastic material in solid mechanics model * * * Copyright (©) 2016-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 "non_linear_solver.hh" #include "patch_test_linear_solid_mechanics_fixture.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; // Stiffness tensor, rotated by hand /* -------------------------------------------------------------------------- */ TYPED_TEST(TestPatchTestSMMLinear, AnisotropicExplicit) { Real C[3][3][3][3] = { {{{112.93753505, 1.85842452538e-10, -4.47654358027e-10}, {1.85847317471e-10, 54.2334345331, -3.69840984824}, {-4.4764768395e-10, -3.69840984824, 56.848605217}}, {{1.85847781609e-10, 25.429294233, -3.69840984816}, {25.429294233, 3.31613847493e-10, -8.38797920011e-11}, {-3.69840984816, -8.38804581349e-11, -1.97875715813e-10}}, {{-4.47654358027e-10, -3.69840984816, 28.044464917}, {-3.69840984816, 2.09374961813e-10, 9.4857455224e-12}, {28.044464917, 9.48308098714e-12, -2.1367885239e-10}}}, {{{1.85847781609e-10, 25.429294233, -3.69840984816}, {25.429294233, 3.31613847493e-10, -8.38793479119e-11}, {-3.69840984816, -8.38795699565e-11, -1.97876381947e-10}}, {{54.2334345331, 3.31617400207e-10, 2.09372075233e-10}, {3.3161562385e-10, 115.552705733, -3.15093728886e-10}, {2.09372075233e-10, -3.15090176173e-10, 54.2334345333}}, {{-3.69840984824, -8.38795699565e-11, 9.48219280872e-12}, {-8.38795699565e-11, -3.1509195253e-10, 25.4292942335}, {9.48441325477e-12, 25.4292942335, 3.69840984851}}}, {{{-4.47653469848e-10, -3.69840984816, 28.044464917}, {-3.69840984816, 2.09374073634e-10, 9.48752187924e-12}, {28.044464917, 9.48552347779e-12, -2.1367885239e-10}}, {{-3.69840984824, -8.3884899027e-11, 9.48219280872e-12}, {-8.3884899027e-11, -3.150972816e-10, 25.4292942335}, {9.48041645188e-12, 25.4292942335, 3.69840984851}}, {{56.848605217, -1.97875493768e-10, -2.13681516925e-10}, {-1.97877270125e-10, 54.2334345333, 3.69840984851}, {-2.13683293282e-10, 3.69840984851, 112.93753505}}}}; if (this->dim == 2) { for (UInt i = 0; i < this->dim; ++i) { for (UInt j = 0; j < this->dim; ++j) { for (UInt k = 0; k < this->dim; ++k) { for (UInt l = 0; l < this->dim; ++l) { C[i][j][k][l] = 0; } } } } C[0][0][0][0] = C[1][1][1][1] = 112.93753504999995; C[0][0][1][1] = C[1][1][0][0] = 51.618263849999984; C[0][1][0][1] = C[1][0][0][1] = C[0][1][1][0] = C[1][0][1][0] = 22.814123549999987; } if (this->dim == 1) { C[0][0][0][0] = 105.092023; } this->initModel(_explicit_lumped_mass, "material_anisotropic_" + std::to_string(this->dim) + ".dat"); const auto & coordinates = this->mesh->getNodes(); auto & displacement = this->model->getDisplacement(); // set the position of all nodes to the static solution for (auto && tuple : zip(make_view(coordinates, this->dim), make_view(displacement, this->dim))) { this->setLinearDOF(std::get<1>(tuple), std::get<0>(tuple)); } for (UInt s = 0; s < 100; ++s) { this->model->solveStep(); } auto ekin = this->model->getEnergy("kinetic"); EXPECT_NEAR(0, ekin, 1e-16); auto & mat = this->model->getMaterial(0); this->checkDOFs(displacement); this->checkGradient(mat.getGradU(this->type), displacement); this->result_tolerance = 1e-11; this->checkResults( [&](const Matrix & pstrain) { auto strain = (pstrain + pstrain.transpose()) / 2.; decltype(strain) stress(this->dim, this->dim); for (UInt i = 0; i < this->dim; ++i) { for (UInt j = 0; j < this->dim; ++j) { stress(i, j) = 0; for (UInt k = 0; k < this->dim; ++k) { for (UInt l = 0; l < this->dim; ++l) { stress(i, j) += C[i][j][k][l] * strain(k, l); } } } } return stress; }, mat.getStress(this->type), displacement); } - -TYPED_TEST(TestPatchTestSMMLinear, AnisotropicStatic) { - Real C[3][3][3][3] = { - {{{112.93753505, 1.85842452538e-10, -4.47654358027e-10}, - {1.85847317471e-10, 54.2334345331, -3.69840984824}, - {-4.4764768395e-10, -3.69840984824, 56.848605217}}, - {{1.85847781609e-10, 25.429294233, -3.69840984816}, - {25.429294233, 3.31613847493e-10, -8.38797920011e-11}, - {-3.69840984816, -8.38804581349e-11, -1.97875715813e-10}}, - {{-4.47654358027e-10, -3.69840984816, 28.044464917}, - {-3.69840984816, 2.09374961813e-10, 9.4857455224e-12}, - {28.044464917, 9.48308098714e-12, -2.1367885239e-10}}}, - {{{1.85847781609e-10, 25.429294233, -3.69840984816}, - {25.429294233, 3.31613847493e-10, -8.38793479119e-11}, - {-3.69840984816, -8.38795699565e-11, -1.97876381947e-10}}, - {{54.2334345331, 3.31617400207e-10, 2.09372075233e-10}, - {3.3161562385e-10, 115.552705733, -3.15093728886e-10}, - {2.09372075233e-10, -3.15090176173e-10, 54.2334345333}}, - {{-3.69840984824, -8.38795699565e-11, 9.48219280872e-12}, - {-8.38795699565e-11, -3.1509195253e-10, 25.4292942335}, - {9.48441325477e-12, 25.4292942335, 3.69840984851}}}, - {{{-4.47653469848e-10, -3.69840984816, 28.044464917}, - {-3.69840984816, 2.09374073634e-10, 9.48752187924e-12}, - {28.044464917, 9.48552347779e-12, -2.1367885239e-10}}, - {{-3.69840984824, -8.3884899027e-11, 9.48219280872e-12}, - {-8.3884899027e-11, -3.150972816e-10, 25.4292942335}, - {9.48041645188e-12, 25.4292942335, 3.69840984851}}, - {{56.848605217, -1.97875493768e-10, -2.13681516925e-10}, - {-1.97877270125e-10, 54.2334345333, 3.69840984851}, - {-2.13683293282e-10, 3.69840984851, 112.93753505}}}}; - - if (this->dim == 2) { - for (UInt i = 0; i < this->dim; ++i) { - for (UInt j = 0; j < this->dim; ++j) { - for (UInt k = 0; k < this->dim; ++k) { - for (UInt l = 0; l < this->dim; ++l) { - C[i][j][k][l] = 0; - } - } - } - } - C[0][0][0][0] = C[1][1][1][1] = 112.93753504999995; - C[0][0][1][1] = C[1][1][0][0] = 51.618263849999984; - C[0][1][0][1] = C[1][0][0][1] = C[0][1][1][0] = C[1][0][1][0] = - 22.814123549999987; - } - - if (this->dim == 1) { - C[0][0][0][0] = 105.092023; - } - - this->initModel(_static, - "material_anisotropic_" + std::to_string(this->dim) + ".dat"); - - auto & solver = this->model->getNonLinearSolver(); - solver.set("max_iterations", 2); - solver.set("threshold", 2e-4); - solver.set("convergence_type", SolveConvergenceCriteria::_residual); - - this->model->solveStep(); - - auto & mat = this->model->getMaterial(0); - - const auto & displacement = this->model->getDisplacement(); - this->checkDOFs(displacement); - this->checkGradient(mat.getGradU(this->type), displacement); - - this->result_tolerance = 1e-11; - this->checkResults( - [&](const Matrix & pstrain) { - auto strain = (pstrain + pstrain.transpose()) / 2.; - decltype(strain) stress(this->dim, this->dim); - - for (UInt i = 0; i < this->dim; ++i) { - for (UInt j = 0; j < this->dim; ++j) { - stress(i, j) = 0; - for (UInt k = 0; k < this->dim; ++k) { - for (UInt l = 0; l < this->dim; ++l) { - stress(i, j) += C[i][j][k][l] * strain(k, l); - } - } - } - } - return stress; - }, - mat.getStress(this->type), displacement); -} diff --git a/test/test_model/patch_tests/patch_test_linear_anisotropic.cc b/test/test_model/patch_tests/patch_test_linear_anisotropic_implicit.cc similarity index 58% rename from test/test_model/patch_tests/patch_test_linear_anisotropic.cc rename to test/test_model/patch_tests/patch_test_linear_anisotropic_implicit.cc index f64b66df7..a9e6e8c37 100644 --- a/test/test_model/patch_tests/patch_test_linear_anisotropic.cc +++ b/test/test_model/patch_tests/patch_test_linear_anisotropic_implicit.cc @@ -1,223 +1,129 @@ /** * @file patch_test_linear_anisotropic_explicit.cc * * @author Guillaume Anciaux * @author Till Junge * @author David Simon Kammer * @author Nicolas Richart * @author Cyprien Wolff * * @date creation: Tue Dec 05 2017 * @date last modification: Tue Feb 13 2018 * * @brief patch test for elastic material in solid mechanics model * * * Copyright (©) 2016-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 "non_linear_solver.hh" #include "patch_test_linear_solid_mechanics_fixture.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; // Stiffness tensor, rotated by hand /* -------------------------------------------------------------------------- */ -TYPED_TEST(TestPatchTestSMMLinear, AnisotropicExplicit) { - Real C[3][3][3][3] = { - {{{112.93753505, 1.85842452538e-10, -4.47654358027e-10}, - {1.85847317471e-10, 54.2334345331, -3.69840984824}, - {-4.4764768395e-10, -3.69840984824, 56.848605217}}, - {{1.85847781609e-10, 25.429294233, -3.69840984816}, - {25.429294233, 3.31613847493e-10, -8.38797920011e-11}, - {-3.69840984816, -8.38804581349e-11, -1.97875715813e-10}}, - {{-4.47654358027e-10, -3.69840984816, 28.044464917}, - {-3.69840984816, 2.09374961813e-10, 9.4857455224e-12}, - {28.044464917, 9.48308098714e-12, -2.1367885239e-10}}}, - {{{1.85847781609e-10, 25.429294233, -3.69840984816}, - {25.429294233, 3.31613847493e-10, -8.38793479119e-11}, - {-3.69840984816, -8.38795699565e-11, -1.97876381947e-10}}, - {{54.2334345331, 3.31617400207e-10, 2.09372075233e-10}, - {3.3161562385e-10, 115.552705733, -3.15093728886e-10}, - {2.09372075233e-10, -3.15090176173e-10, 54.2334345333}}, - {{-3.69840984824, -8.38795699565e-11, 9.48219280872e-12}, - {-8.38795699565e-11, -3.1509195253e-10, 25.4292942335}, - {9.48441325477e-12, 25.4292942335, 3.69840984851}}}, - {{{-4.47653469848e-10, -3.69840984816, 28.044464917}, - {-3.69840984816, 2.09374073634e-10, 9.48752187924e-12}, - {28.044464917, 9.48552347779e-12, -2.1367885239e-10}}, - {{-3.69840984824, -8.3884899027e-11, 9.48219280872e-12}, - {-8.3884899027e-11, -3.150972816e-10, 25.4292942335}, - {9.48041645188e-12, 25.4292942335, 3.69840984851}}, - {{56.848605217, -1.97875493768e-10, -2.13681516925e-10}, - {-1.97877270125e-10, 54.2334345333, 3.69840984851}, - {-2.13683293282e-10, 3.69840984851, 112.93753505}}}}; - - if (this->dim == 2) { - for (UInt i = 0; i < this->dim; ++i) { - for (UInt j = 0; j < this->dim; ++j) { - for (UInt k = 0; k < this->dim; ++k) { - for (UInt l = 0; l < this->dim; ++l) { - C[i][j][k][l] = 0; - } - } - } - } - C[0][0][0][0] = C[1][1][1][1] = 112.93753504999995; - C[0][0][1][1] = C[1][1][0][0] = 51.618263849999984; - C[0][1][0][1] = C[1][0][0][1] = C[0][1][1][0] = C[1][0][1][0] = - 22.814123549999987; - } - - if (this->dim == 1) { - C[0][0][0][0] = 105.092023; - } - this->initModel(_explicit_lumped_mass, - "material_anisotropic_" + std::to_string(this->dim) + ".dat"); - - const auto & coordinates = this->mesh->getNodes(); - auto & displacement = this->model->getDisplacement(); - - // set the position of all nodes to the static solution - for (auto && tuple : zip(make_view(coordinates, this->dim), - make_view(displacement, this->dim))) { - this->setLinearDOF(std::get<1>(tuple), std::get<0>(tuple)); - } - - for (UInt s = 0; s < 100; ++s) { - this->model->solveStep(); - } - - auto ekin = this->model->getEnergy("kinetic"); - EXPECT_NEAR(0, ekin, 1e-16); - - auto & mat = this->model->getMaterial(0); - - this->checkDOFs(displacement); - this->checkGradient(mat.getGradU(this->type), displacement); - - this->result_tolerance = 1e-11; - this->checkResults( - [&](const Matrix & pstrain) { - auto strain = (pstrain + pstrain.transpose()) / 2.; - decltype(strain) stress(this->dim, this->dim); - - for (UInt i = 0; i < this->dim; ++i) { - for (UInt j = 0; j < this->dim; ++j) { - stress(i, j) = 0; - for (UInt k = 0; k < this->dim; ++k) { - for (UInt l = 0; l < this->dim; ++l) { - stress(i, j) += C[i][j][k][l] * strain(k, l); - } - } - } - } - return stress; - }, - mat.getStress(this->type), displacement); -} - TYPED_TEST(TestPatchTestSMMLinear, AnisotropicStatic) { Real C[3][3][3][3] = { {{{112.93753505, 1.85842452538e-10, -4.47654358027e-10}, {1.85847317471e-10, 54.2334345331, -3.69840984824}, {-4.4764768395e-10, -3.69840984824, 56.848605217}}, {{1.85847781609e-10, 25.429294233, -3.69840984816}, {25.429294233, 3.31613847493e-10, -8.38797920011e-11}, {-3.69840984816, -8.38804581349e-11, -1.97875715813e-10}}, {{-4.47654358027e-10, -3.69840984816, 28.044464917}, {-3.69840984816, 2.09374961813e-10, 9.4857455224e-12}, {28.044464917, 9.48308098714e-12, -2.1367885239e-10}}}, {{{1.85847781609e-10, 25.429294233, -3.69840984816}, {25.429294233, 3.31613847493e-10, -8.38793479119e-11}, {-3.69840984816, -8.38795699565e-11, -1.97876381947e-10}}, {{54.2334345331, 3.31617400207e-10, 2.09372075233e-10}, {3.3161562385e-10, 115.552705733, -3.15093728886e-10}, {2.09372075233e-10, -3.15090176173e-10, 54.2334345333}}, {{-3.69840984824, -8.38795699565e-11, 9.48219280872e-12}, {-8.38795699565e-11, -3.1509195253e-10, 25.4292942335}, {9.48441325477e-12, 25.4292942335, 3.69840984851}}}, {{{-4.47653469848e-10, -3.69840984816, 28.044464917}, {-3.69840984816, 2.09374073634e-10, 9.48752187924e-12}, {28.044464917, 9.48552347779e-12, -2.1367885239e-10}}, {{-3.69840984824, -8.3884899027e-11, 9.48219280872e-12}, {-8.3884899027e-11, -3.150972816e-10, 25.4292942335}, {9.48041645188e-12, 25.4292942335, 3.69840984851}}, {{56.848605217, -1.97875493768e-10, -2.13681516925e-10}, {-1.97877270125e-10, 54.2334345333, 3.69840984851}, {-2.13683293282e-10, 3.69840984851, 112.93753505}}}}; if (this->dim == 2) { for (UInt i = 0; i < this->dim; ++i) { for (UInt j = 0; j < this->dim; ++j) { for (UInt k = 0; k < this->dim; ++k) { for (UInt l = 0; l < this->dim; ++l) { C[i][j][k][l] = 0; } } } } C[0][0][0][0] = C[1][1][1][1] = 112.93753504999995; C[0][0][1][1] = C[1][1][0][0] = 51.618263849999984; C[0][1][0][1] = C[1][0][0][1] = C[0][1][1][0] = C[1][0][1][0] = 22.814123549999987; } if (this->dim == 1) { C[0][0][0][0] = 105.092023; } this->initModel(_static, "material_anisotropic_" + std::to_string(this->dim) + ".dat"); auto & solver = this->model->getNonLinearSolver(); solver.set("max_iterations", 2); solver.set("threshold", 2e-4); solver.set("convergence_type", SolveConvergenceCriteria::_residual); this->model->solveStep(); auto & mat = this->model->getMaterial(0); const auto & displacement = this->model->getDisplacement(); this->checkDOFs(displacement); this->checkGradient(mat.getGradU(this->type), displacement); this->result_tolerance = 1e-11; this->checkResults( [&](const Matrix & pstrain) { auto strain = (pstrain + pstrain.transpose()) / 2.; decltype(strain) stress(this->dim, this->dim); for (UInt i = 0; i < this->dim; ++i) { for (UInt j = 0; j < this->dim; ++j) { stress(i, j) = 0; for (UInt k = 0; k < this->dim; ++k) { for (UInt l = 0; l < this->dim; ++l) { stress(i, j) += C[i][j][k][l] * strain(k, l); } } } } return stress; }, mat.getStress(this->type), displacement); } diff --git a/test/test_model/patch_tests/patch_test_linear_elastic_explicit.cc b/test/test_model/patch_tests/patch_test_linear_elastic_explicit.cc index 54dc61d42..fb0a39e83 100644 --- a/test/test_model/patch_tests/patch_test_linear_elastic_explicit.cc +++ b/test/test_model/patch_tests/patch_test_linear_elastic_explicit.cc @@ -1,97 +1,97 @@ /** * @file patch_test_linear_elastic_explicit.cc * * @author Nicolas Richart * * @date creation: Tue Jan 30 2018 * * @brief patch test solid mechanics explicit * * * Copyright (©) 2016-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 "patch_test_linear_solid_mechanics_fixture.hh" /* -------------------------------------------------------------------------- */ TYPED_TEST(TestPatchTestSMMLinear, Explicit) { std::string filename = "material_check_stress_plane_stress.dat"; if (this->plane_strain) filename = "material_check_stress_plane_strain.dat"; this->initModel(_explicit_lumped_mass, filename); const auto & coordinates = this->mesh->getNodes(); auto & displacement = this->model->getDisplacement(); // set the position of all nodes to the static solution for (auto && tuple : zip(make_view(coordinates, this->dim), make_view(displacement, this->dim))) { this->setLinearDOF(std::get<1>(tuple), std::get<0>(tuple)); } for (UInt s = 0; s < 100; ++s) { this->model->solveStep(); } auto ekin = this->model->getEnergy("kinetic"); EXPECT_NEAR(0, ekin, 1e-16); this->checkAll(); #define debug 0 #if debug this->model->setBaseName(std::to_string(this->type) + "_explicit"); this->model->addDumpField("stress"); this->model->addDumpField("grad_u"); this->model->addDumpFieldVector("internal_force"); this->model->addDumpFieldVector("external_force"); this->model->addDumpField("blocked_dofs"); this->model->addDumpFieldVector("displacement"); this->model->dump(); #endif } /* -------------------------------------------------------------------------- */ TYPED_TEST(TestPatchTestSMMLinear, ExplicitFiniteDeformation) { std::string filename = "material_check_stress_plane_stress_finite_deformation.dat"; - if (this->plane_strain) + if (this->plane_strain) { filename = "material_check_stress_plane_strain_finite_deformation.dat"; - else { + } else { SUCCEED(); return; } this->initModel(_explicit_lumped_mass, filename); const auto & coordinates = this->mesh->getNodes(); auto & displacement = this->model->getDisplacement(); // set the position of all nodes to the static solution for (auto && tuple : zip(make_view(coordinates, this->dim), make_view(displacement, this->dim))) { this->setLinearDOF(std::get<1>(tuple), std::get<0>(tuple)); } for (UInt s = 0; s < 100; ++s) { this->model->solveStep(); } auto ekin = this->model->getEnergy("kinetic"); EXPECT_NEAR(0, ekin, 1e-16); this->checkAll(); } diff --git a/test/test_model/test_solid_mechanics_model/CMakeLists.txt b/test/test_model/test_solid_mechanics_model/CMakeLists.txt index 098d9aa5e..8a312f6e4 100644 --- a/test/test_model/test_solid_mechanics_model/CMakeLists.txt +++ b/test/test_model/test_solid_mechanics_model/CMakeLists.txt @@ -1,82 +1,81 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux # # @date creation: Fri Sep 03 2010 # @date last modification: Tue Jan 30 2018 # # @brief configuratio for SolidMechanicsModel tests # # @section LICENSE # # 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 . # # @section DESCRIPTION # #=============================================================================== add_akantu_test(test_materials "test_materials") add_akantu_test(test_cohesive "cohesive_test") add_akantu_test(test_embedded_interface "test_embedded_interface") add_akantu_test(test_energies "test energies") #=============================================================================== #=============================================================================== add_mesh(test_cube3d_two_mat_mesh cube_two_materials.geo 3 1) register_test(test_solid_mechanics_model_reassign_material SOURCES test_solid_mechanics_model_reassign_material.cc DEPENDS test_cube3d_two_mat_mesh FILES_TO_COPY two_materials.dat PACKAGE parallel implicit PARALLEL ) #=============================================================================== register_test(test_solid_mechanics_model_material_eigenstrain SOURCES test_solid_mechanics_model_material_eigenstrain.cc FILES_TO_COPY cube_3d_tet_4.msh; material_elastic_plane_strain.dat PACKAGE implicit ) #=============================================================================== register_test(test_solid_mechanics_model_material_large_rotation SOURCES test_solid_mechanics_model_material_large_rotation.cc FILES_TO_COPY cube_3d_tet_4.msh; material_elastic.dat PACKAGE implicit UNSTABLE ) #=============================================================================== - register_test(test_material_selector SOURCES test_material_selector.cc FILES_TO_COPY material_selector.dat material_selector.msh PACKAGE core ) #=============================================================================== # dynamics tests #=============================================================================== register_gtest_sources( SOURCES test_solid_mechanics_model_dynamics.cc FILES_TO_COPY test_solid_mechanics_model_dynamics_material.dat PACKAGE core ) register_gtest_test(test_solid_mechanics_model DEPENDS ${PATCH_TEST_BAR_MESHES} #bar_segment_2 bar_segment_3 #bar_triangle_3 bar_triangle_6 #bar_quadrangle_4 bar_quadrangle_8 #bar_tetrahedron_4 bar_tetrahedron_10 #bar_hexahedron_8 bar_hexahedron_20 #bar_pentahedron_6 bar_pentahedron_15 PARALLEL ) diff --git a/test/test_model/test_solid_mechanics_model/test_cohesive/test_cohesive_insertion/test_cohesive_insertion_along_physical_surfaces.cc b/test/test_model/test_solid_mechanics_model/test_cohesive/test_cohesive_insertion/test_cohesive_insertion_along_physical_surfaces.cc index 2418b68f4..fcc009c83 100644 --- a/test/test_model/test_solid_mechanics_model/test_cohesive/test_cohesive_insertion/test_cohesive_insertion_along_physical_surfaces.cc +++ b/test/test_model/test_solid_mechanics_model/test_cohesive/test_cohesive_insertion/test_cohesive_insertion_along_physical_surfaces.cc @@ -1,91 +1,91 @@ /** * @file test_cohesive_insertion_along_physical_surfaces.cc * * @author Fabian Barras * * @date creation: Fri Aug 07 2015 * @date last modification: Mon Dec 18 2017 * * @brief Test intrinsic insertion of cohesive elements along physical surfaces * * * 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 "aka_common.hh" #include "material.hh" #include "material_cohesive.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" #include "mesh_utils.hh" #include "solid_mechanics_model_cohesive.hh" /* -------------------------------------------------------------------------- */ #include #include #include /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char * argv[]) { initialize("input_file.dat", argc, argv); Math::setTolerance(1e-15); const UInt spatial_dimension = 3; Mesh mesh(spatial_dimension); mesh.read("3d_spherical_inclusion.msh"); SolidMechanicsModelCohesive model(mesh); auto && material_selector = std::make_shared(model); material_selector->setFallback(model.getMaterialSelector()); model.setMaterialSelector(material_selector); - model.initFull(_analysis_method = _static); + model.initFull(); std::vector surfaces_name = {"interface", "coh1", "coh2", "coh3", "coh4", "coh5"}; UInt nb_surf = surfaces_name.size(); for (auto & type : mesh.elementTypes(spatial_dimension, _not_ghost, _ek_cohesive)) { for (UInt i = 0; i < nb_surf; ++i) { UInt expected_insertion = mesh.getElementGroup(surfaces_name[i]) .getElements(mesh.getFacetType(type)) .size(); UInt inserted_elements = model.getMaterial(surfaces_name[i]).getElementFilter()(type).size(); if (not(expected_insertion == inserted_elements)) { std::cout << "!!! Mismatch in insertion of surface named " << surfaces_name[i] << " --> " << inserted_elements << " inserted elements out of " << expected_insertion << std::endl; return 1; } } } return 0; } diff --git a/test/test_model/test_solid_mechanics_model/test_materials/test_material_elasto_plastic_linear_isotropic_hardening/CMakeLists.txt b/test/test_model/test_solid_mechanics_model/test_materials/test_material_elasto_plastic_linear_isotropic_hardening/CMakeLists.txt index 7e37f5f40..3b10d8256 100644 --- a/test/test_model/test_solid_mechanics_model/test_materials/test_material_elasto_plastic_linear_isotropic_hardening/CMakeLists.txt +++ b/test/test_model/test_solid_mechanics_model/test_materials/test_material_elasto_plastic_linear_isotropic_hardening/CMakeLists.txt @@ -1,38 +1,38 @@ #=============================================================================== # @file CMakeLists.txt # # @author Jaehyun Cho # # @date creation: Fri Oct 22 2010 # @date last modification: Wed Mar 09 2016 # # @brief test for material type elasto plastic linear isotropic hardening using # tension-compression test # # @section LICENSE # # 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 . # # @section DESCRIPTION # #=============================================================================== #=============================================================================== add_mesh(test_material_standard_linear_isotropic_hardening_mesh test_material_elasto_plastic_linear_isotropic_hardening.geo 2 1) register_test(test_material_standard_linear_isotropic_hardening SOURCES test_material_elasto_plastic_linear_isotropic_hardening.cc DEPENDS test_material_standard_linear_isotropic_hardening_mesh FILES_TO_COPY test_material_elasto_plastic_linear_isotropic_hardening.dat - PACKAGE core + PACKAGE core implicit ) #=============================================================================== diff --git a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_dynamics.cc b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_dynamics.cc index e2ab0f799..61fdad515 100644 --- a/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_dynamics.cc +++ b/test/test_model/test_solid_mechanics_model/test_solid_mechanics_model_dynamics.cc @@ -1,318 +1,320 @@ /** * @file test_solid_mechanics_model_dynamics.cc * * @author Guillaume Anciaux * * @date creation: Wed Nov 29 2017 * @date last modification: Wed Feb 21 2018 * * @brief test of the class SolidMechanicsModel on the 3d cube * * * Copyright (©) 2016-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 "boundary_condition_functor.hh" #include "test_solid_mechanics_model_fixture.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; namespace { const Real A = 1e-1; const Real E = 1.; const Real poisson = 3. / 10; const Real lambda = E * poisson / (1 + poisson) / (1 - 2 * poisson); const Real mu = E / 2 / (1. + poisson); const Real rho = 1.; const Real cp = std::sqrt((lambda + 2 * mu) / rho); const Real cs = std::sqrt(mu / rho); const Real c = std::sqrt(E / rho); const Vector k = {.5, 0., 0.}; const Vector psi1 = {0., 0., 1.}; const Vector psi2 = {0., 1., 0.}; const Real knorm = k.norm(); /* -------------------------------------------------------------------------- */ template struct Verification {}; /* -------------------------------------------------------------------------- */ template <> struct Verification<1> { void displacement(Vector & disp, const Vector & coord, Real current_time) { const auto & x = coord(_x); const Real omega = c * k[0]; disp(_x) = A * cos(k[0] * x - omega * current_time); } void velocity(Vector & vel, const Vector & coord, Real current_time) { const auto & x = coord(_x); const Real omega = c * k[0]; vel(_x) = omega * A * sin(k[0] * x - omega * current_time); } }; /* -------------------------------------------------------------------------- */ template <> struct Verification<2> { void displacement(Vector & disp, const Vector & X, Real current_time) { Vector kshear = {k[1], k[0]}; Vector kpush = {k[0], k[1]}; const Real omega_p = knorm * cp; const Real omega_s = knorm * cs; Real phase_p = X.dot(kpush) - omega_p * current_time; Real phase_s = X.dot(kpush) - omega_s * current_time; disp = A * (kpush * cos(phase_p) + kshear * cos(phase_s)); } void velocity(Vector & vel, const Vector & X, Real current_time) { Vector kshear = {k[1], k[0]}; Vector kpush = {k[0], k[1]}; const Real omega_p = knorm * cp; const Real omega_s = knorm * cs; Real phase_p = X.dot(kpush) - omega_p * current_time; Real phase_s = X.dot(kpush) - omega_s * current_time; vel = A * (kpush * omega_p * cos(phase_p) + kshear * omega_s * cos(phase_s)); } }; /* -------------------------------------------------------------------------- */ template <> struct Verification<3> { void displacement(Vector & disp, const Vector & coord, Real current_time) { const auto & X = coord; Vector kpush = k; Vector kshear1(3); Vector kshear2(3); kshear1.crossProduct(k, psi1); kshear2.crossProduct(k, psi2); const Real omega_p = knorm * cp; const Real omega_s = knorm * cs; Real phase_p = X.dot(kpush) - omega_p * current_time; Real phase_s = X.dot(kpush) - omega_s * current_time; disp = A * (kpush * cos(phase_p) + kshear1 * cos(phase_s) + kshear2 * cos(phase_s)); } void velocity(Vector & vel, const Vector & coord, Real current_time) { const auto & X = coord; Vector kpush = k; Vector kshear1(3); Vector kshear2(3); kshear1.crossProduct(k, psi1); kshear2.crossProduct(k, psi2); const Real omega_p = knorm * cp; const Real omega_s = knorm * cs; Real phase_p = X.dot(kpush) - omega_p * current_time; Real phase_s = X.dot(kpush) - omega_s * current_time; vel = A * (kpush * omega_p * cos(phase_p) + kshear1 * omega_s * cos(phase_s) + kshear2 * omega_s * cos(phase_s)); } }; /* -------------------------------------------------------------------------- */ template class SolutionFunctor : public BC::Dirichlet::DirichletFunctor { public: SolutionFunctor(Real current_time, SolidMechanicsModel & model) : current_time(current_time), model(model) {} public: static constexpr UInt dim = ElementClass<_type>::getSpatialDimension(); inline void operator()(UInt node, Vector & flags, Vector & primal, const Vector & coord) const { flags(0) = true; auto & vel = model.getVelocity(); auto it = vel.begin(model.getSpatialDimension()); Vector v = it[node]; Verification verif; verif.displacement(primal, coord, current_time); verif.velocity(v, coord, current_time); } private: Real current_time; SolidMechanicsModel & model; }; /* -------------------------------------------------------------------------- */ // This fixture uses somewhat finer meshes representing bars. template class TestSMMFixtureBar : public TestSMMFixture { using parent = TestSMMFixture; public: void SetUp() override { this->mesh_file = "../patch_tests/data/bar" + std::to_string(this->type) + ".msh"; parent::SetUp(); auto analysis_method = analysis_method_::value; this->initModel("test_solid_mechanics_model_" "dynamics_material.dat", analysis_method); const auto & position = this->mesh->getNodes(); auto & displacement = this->model->getDisplacement(); auto & velocity = this->model->getVelocity(); constexpr auto dim = parent::spatial_dimension; Verification verif; for (auto && tuple : zip(make_view(position, dim), make_view(displacement, dim), make_view(velocity, dim))) { verif.displacement(std::get<1>(tuple), std::get<0>(tuple), 0.); verif.velocity(std::get<2>(tuple), std::get<0>(tuple), 0.); } if (this->dump_paraview) this->model->dump(); /// boundary conditions this->model->applyBC(SolutionFunctor(0., *this->model), "BC"); wave_velocity = 1.; // sqrt(E/rho) = sqrt(1/1) = 1 simulation_time = 5 / wave_velocity; time_step = this->model->getTimeStep(); max_steps = simulation_time / time_step; // 100 } void solveStep() { constexpr auto dim = parent::spatial_dimension; Real current_time = 0.; const auto & position = this->mesh->getNodes(); const auto & displacement = this->model->getDisplacement(); UInt nb_nodes = this->mesh->getNbNodes(); UInt nb_global_nodes = this->mesh->getNbGlobalNodes(); max_error = -1.; Array displacement_solution(nb_nodes, dim); Verification verif; auto ndump = 50; auto dump_freq = max_steps / ndump; for (UInt s = 0; s < this->max_steps; ++s, current_time += this->time_step) { if (s % dump_freq == 0 && this->dump_paraview) this->model->dump(); /// boundary conditions this->model->applyBC( SolutionFunctor(current_time, *this->model), "BC"); // compute the disp solution for (auto && tuple : zip(make_view(position, dim), make_view(displacement_solution, dim))) { verif.displacement(std::get<1>(tuple), std::get<0>(tuple), current_time); } // compute the error solution Real disp_error = 0.; auto n = 0; for (auto && tuple : zip(make_view(displacement, dim), make_view(displacement_solution, dim))) { if (this->mesh->isLocalOrMasterNode(n)) { auto diff = std::get<1>(tuple) - std::get<0>(tuple); disp_error += diff.dot(diff); } ++n; } this->mesh->getCommunicator().allReduce(disp_error, SynchronizerOperation::_sum); disp_error = sqrt(disp_error) / nb_global_nodes; max_error = std::max(disp_error, max_error); this->model->solveStep(); } } protected: Real time_step; Real wave_velocity; Real simulation_time; UInt max_steps; Real max_error{-1}; }; template using analysis_method_t = std::integral_constant; using TestTypes = gtest_list_t; template using TestSMMFixtureBarExplicit = TestSMMFixtureBar>; TYPED_TEST_SUITE(TestSMMFixtureBarExplicit, TestTypes); /* -------------------------------------------------------------------------- */ TYPED_TEST(TestSMMFixtureBarExplicit, Dynamics) { this->solveStep(); EXPECT_NEAR(this->max_error, 0., 2e-3); // std::cout << "max error: " << max_error << std::endl; } /* -------------------------------------------------------------------------- */ +#if defined(AKANTU_IMPLICIT) template using TestSMMFixtureBarImplicit = TestSMMFixtureBar>; TYPED_TEST_SUITE(TestSMMFixtureBarImplicit, TestTypes); TYPED_TEST(TestSMMFixtureBarImplicit, Dynamics) { if (this->type == _segment_2 and (this->mesh->getCommunicator().getNbProc() > 2)) { // The error are just to high after (hopefully because of the two small test // case) SUCCEED(); return; } this->solveStep(); EXPECT_NEAR(this->max_error, 0., 2e-3); } +#endif } // namespace