diff --git a/tests/split_test_laminate_solver.cc b/tests/split_test_laminate_solver.cc index 9ca4282..9457242 100644 --- a/tests/split_test_laminate_solver.cc +++ b/tests/split_test_laminate_solver.cc @@ -1,199 +1,172 @@ /** * @file test_laminate_solver.cc * * @author Till Junge * * @date 19 Oct 2018 * * @brief Tests for the large-strain, laminate homogenisation algorithm * * Copyright © 2017 Till Junge * * µSpectre is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3, or (at * your option) any later version. * * µSpectre 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 * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Emacs; see the file COPYING. If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include #include #include #include "materials/material_linear_elastic1.hh" #include "materials/material_linear_elastic2.hh" #include "materials/material_orthotropic.hh" #include "materials/laminate_homogenisation.hh" #include "tests.hh" #include "tests/test_goodies.hh" #include "common/field_collection.hh" #include "common/iterators.hh" namespace muSpectre{ BOOST_AUTO_TEST_SUITE(laminate_homogenisation); + + struct inputs{ + // constructor : + inputs(Real c): + c{c}{}; + + Real c; + Real lambda1{2}, mu1{1.5}; + Real lambda2{c*lambda1}, mu2{c*mu1}; + Real young1{mu1*(3*lambda1 + 2*mu1)/(lambda1 + mu1)}; + Real young2{mu2*(3*lambda2 + 2*mu2)/(lambda2 + mu2)}; + Real poisson1{lambda1/(2*(lambda1 + mu1))}; + Real poisson2{lambda2/(2*(lambda2 + mu2))}; + + std::array ortho_inp1_3D {1.1,2.1,3.1,4.1,5.1,6.1,7.1,8.1,9.1}; + std::array ortho_inp2_3D {c*1.1,c*2.1,c*3.1,c*4.1, + c*5.1,c*6.1,c*7.1,c*8.1,c*9.1}; + std::array aniso_inp1_3D {1.1,2.1,3.1,4.1,5.1,6.1,7.1,8.1,9.1,10.1, + 11.1,12.1,13.1,14.1,15.1,16.1,17.1,18.1,19.1,20.1,21.1}; + std::array aniso_inp2_3D {c*1.1,c*2.1,c*3.1,c*4.1,c*5.1,c*6.1,c*7.1,c*8.1,c*9.1,c*10.1, + c*11.1,c*12.1,c*13.1,c*14.1,c*15.1,c*16.1,c*17.1,c*18.1,c*19.1,c*20.1,c*21.1}; + + std::array ortho_inp1_2D {1.1,2.1,3.1,4.1}; + std::array ortho_inp2_2D {c*1.1,c*2.1,c*3.1,c*4.1}; + std::array aniso_inp1_2D {1.1,2.1,3.1,4.1,5.1,6.1}; + std::array aniso_inp2_2D {c*1.1,c*2.1,c*3.1,c*4.1,c*5.1,c*6.1}; + }; + template + struct MaterialsFixture { using Vec_t = Eigen::Matrix; using Stiffness_t = T4Mat; using Serial_stiffness_t = Eigen::Matrix; using Parallel_stiffness_t = T4Mat; using Strain_t = Eigen::Matrix; using Serial_strain_t = Eigen::Matrix; using Parallel_strain_t = Eigen::Matrix; using Stress_t = Strain_t; using Serial_stress_t = Serial_strain_t; using Paralle_stress_t = Parallel_strain_t; using StrainMap_t = Eigen::Matrix; using StressMap_t = StrainMap_t; using T4MatMap_t = Eigen::Map>; using Function_t = std::function (const Eigen::Ref &)>; - constexpr static double contrast = 1.0 ; - constexpr static Real lambda1{2}, mu1{1.5}; - constexpr static Real lambda2{contrast*lambda1}, mu2{contrast*mu1}; - constexpr static Real young1{mu1*(3*lambda1 + 2*mu1)/(lambda1 + mu1)}; - constexpr static Real young2{mu2*(3*lambda2 + 2*mu2)/(lambda2 + mu2)}; - constexpr static Real poisson1{lambda1/(2*(lambda1 + mu1))}; - constexpr static Real poisson2{lambda2/(2*(lambda2 + mu2))}; - - // constructor : MaterialsFixture(); // constructor with th e normal vector: - MaterialsFixture(Vec_t normal_vec_inp):mat1("Name1", young1, poisson1), - mat2("Name2", young2, poisson2), - normal_vec{normal_vec_inp} - {}; - Mat1_t mat1; - Mat2_t mat2; + MaterialsFixture(Mat1_t* mat1, Mat2_t* mat2) + { + this->mat1 = mat1; + this->mat2 = mat2; + }; + + virtual ~MaterialsFixture() = default; + Mat1_t mat1{}; + Mat2_t mat2{}; Vec_t normal_vec{Vec_t::Random()}; static constexpr Dim_t fix_dim{Dim}; - }; - - template<> - MaterialsFixture, - MaterialLinearElastic1, threeD>:: MaterialsFixture():mat1("Name1", young1, poisson1), - mat2("Name2", young2, poisson2){} - template<> - MaterialsFixture, - MaterialLinearElastic1, twoD>:: MaterialsFixture():mat1("Name1", young1, poisson1), - mat2("Name2", young2, poisson2){} - Real c{1.0}; - std::array ortho_inp1_3D {1.1,2.1,3.1,4.1,5.1,6.1,7.1,8.1,9.1}; - std::array ortho_inp2_3D {c*1.1,c*2.1,c*3.1,c*4.1, - c*5.1,c*6.1,c*7.1,c*8.1,c*9.1}; - std::array aniso_inp1_3D {1.1,2.1,3.1,4.1,5.1,6.1,7.1,8.1,9.1,10.1, - 11.1,12.1,13.1,14.1,15.1,16.1,17.1,18.1,19.1,20.1,21.1}; - std::array aniso_inp2_3D {c*1.1,c*2.1,c*3.1,c*4.1,c*5.1,c*6.1,c*7.1,c*8.1,c*9.1,c*10.1, - c*11.1,c*12.1,c*13.1,c*14.1,c*15.1,c*16.1,c*17.1,c*18.1,c*19.1,c*20.1,c*21.1}; - - - std::array ortho_inp1_2D {1.1,2.1,3.1,4.1}; - std::array ortho_inp2_2D {c*1.1,c*2.1,c*3.1,c*4.1}; - std::array aniso_inp1_2D {1.1,2.1,3.1,4.1,5.1,6.1}; - std::array aniso_inp2_2D {c*1.1,c*2.1,c*3.1,c*4.1,c*5.1,c*6.1}; - - template<> - MaterialsFixture, - MaterialOrthotropic, threeD>:: - MaterialsFixture():mat1("Name1", std::vector {ortho_inp1_3D.begin(), ortho_inp1_3D.end()}), - mat2("Name2", std::vector {ortho_inp2_3D.begin(), ortho_inp2_3D.end()}){} - template<> - MaterialsFixture, - MaterialAnisotropic, threeD>:: - MaterialsFixture():mat1("Name1", std::vector {aniso_inp1_3D.begin(), aniso_inp1_3D.end()}), - mat2("Name2", std::vector {aniso_inp2_3D.begin(), aniso_inp2_3D.end()}){} - - template<> - MaterialsFixture, - MaterialOrthotropic, twoD>:: - MaterialsFixture():mat1("Name1", std::vector {ortho_inp1_2D.begin(), ortho_inp1_2D.end()}), - mat2("Name2", std::vector {ortho_inp2_2D.begin(), ortho_inp2_2D.end()}){} - template<> - MaterialsFixture, - MaterialAnisotropic, twoD>:: - MaterialsFixture():mat1("Name1", std::vector {aniso_inp1_2D.begin(), aniso_inp1_2D.end()}), - mat2("Name2", std::vector {aniso_inp2_2D.begin(), aniso_inp2_2D.end()}){} - + inputs inp1 (1.0); + MaterialLinearElastic1 &&mat_lin_1 = + MaterialLinearElastic1("material_linear_elastic1_1", inp1.young1, inp1.mu1); + MaterialLinearElastic1 &&mat_lin_2 = + MaterialLinearElastic1("material_linear_elastic1_2", inp1.young1, inp1.mu1); using fix_list = boost::mpl::list - , - MaterialAnisotropic, threeD>, - MaterialsFixture, - MaterialAnisotropic, twoD>, - MaterialsFixture, - MaterialOrthotropic, threeD>, - MaterialsFixture, - MaterialOrthotropic, twoD>, - MaterialsFixture, - MaterialLinearElastic1, threeD>, - MaterialsFixture, - MaterialLinearElastic1, twoD>>; + , + MaterialLinearElastic1, threeD> + (&mat_lin_1, + &mat_lin_2)>; BOOST_FIXTURE_TEST_CASE_TEMPLATE(identical_material, Fix, fix_list, Fix) { auto & mat1{Fix::mat1}; auto & mat2{Fix::mat2}; using Strain_t = typename Fix::Strain_t; using StrainMap_t = typename Fix::StrainMap_t; StrainMap_t F; F = StrainMap_t::Random(); using Fucntion_t = typename Fix::Function_t; Fucntion_t mat1_evaluate_stress_func = [&mat1](const Eigen::Ref & strain){ return mat1.evaluate_stress_tangent(std::move(strain)); }; Fucntion_t mat2_evaluate_stress_func = [&mat2](const Eigen::Ref & strain){ return mat2.evaluate_stress_tangent(std::move(strain)); }; auto P_K_lam = LamHomogen::laminate_solver(Eigen::Map(F.data()), mat1_evaluate_stress_func, mat2_evaluate_stress_func, 0.5, Fix::normal_vec, 1e-8, 1e5); auto P_lam = std::get<0> (P_K_lam); auto K_lam = std::get<1> (P_K_lam); auto P_K_ref = mat1_evaluate_stress_func(F); auto P_ref = std::get<0> (P_K_ref); auto K_ref = std::get<1> (P_K_ref); auto err_P{(P_lam - P_ref).norm()}; auto err_K{(K_lam - K_ref).norm()}; BOOST_CHECK_LT(err_P, tol); BOOST_CHECK_LT(err_K, tol); }; BOOST_AUTO_TEST_SUITE_END(); } //muSpectre