Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #include "PointwiseFunctions/Elasticity/ConstitutiveRelations/IsotropicHomogeneous.hpp" 5 : 6 : #include <array> 7 : #include <pup.h> // IWYU pragma: keep 8 : 9 : #include "DataStructures/DataVector.hpp" 10 : #include "DataStructures/Tensor/Tensor.hpp" // IWYU pragma: keep 11 : #include "DataStructures/Tensor/TypeAliases.hpp" 12 : #include "Utilities/GenerateInstantiations.hpp" 13 : #include "Utilities/Gsl.hpp" 14 : #include "Utilities/MakeWithValue.hpp" 15 : 16 : namespace Elasticity::ConstitutiveRelations { 17 : 18 : template <size_t Dim> 19 : IsotropicHomogeneous<Dim>::IsotropicHomogeneous(double bulk_modulus, 20 : double shear_modulus) noexcept 21 : : bulk_modulus_(bulk_modulus), shear_modulus_(shear_modulus) {} 22 : 23 : template <> 24 0 : void IsotropicHomogeneous<3>::stress( 25 : const gsl::not_null<tnsr::II<DataVector, 3>*> stress, 26 : const tnsr::ii<DataVector, 3>& strain, 27 : const tnsr::I<DataVector, 3>& /*x*/) const noexcept { 28 : for (size_t i = 0; i < 3; ++i) { 29 : for (size_t j = 0; j <= i; ++j) { 30 : stress->get(i, j) = -2. * shear_modulus_ * strain.get(i, j); 31 : } 32 : } 33 : auto trace_term = make_with_value<DataVector>(strain, 0.); 34 : for (size_t i = 0; i < 3; ++i) { 35 : trace_term += strain.get(i, i); 36 : } 37 : trace_term *= lame_parameter(); 38 : for (size_t i = 0; i < 3; ++i) { 39 : stress->get(i, i) -= trace_term; 40 : } 41 : } 42 : 43 : template <> 44 0 : void IsotropicHomogeneous<2>::stress( 45 : const gsl::not_null<tnsr::II<DataVector, 2>*> stress, 46 : const tnsr::ii<DataVector, 2>& strain, 47 : const tnsr::I<DataVector, 2>& /*x*/) const noexcept { 48 : for (size_t i = 0; i < 2; ++i) { 49 : for (size_t j = 0; j <= i; ++j) { 50 : stress->get(i, j) = -2. * shear_modulus_ * strain.get(i, j); 51 : } 52 : } 53 : auto trace_term = make_with_value<DataVector>(strain, 0.); 54 : for (size_t i = 0; i < 2; ++i) { 55 : trace_term += strain.get(i, i); 56 : } 57 : trace_term *= 2. * (3. * bulk_modulus_ - 2. * shear_modulus_) * 58 : shear_modulus_ / (3. * bulk_modulus_ + 4. * shear_modulus_); 59 : for (size_t i = 0; i < 2; ++i) { 60 : stress->get(i, i) -= trace_term; 61 : } 62 : } 63 : 64 : template <size_t Dim> 65 : double IsotropicHomogeneous<Dim>::bulk_modulus() const noexcept { 66 : return bulk_modulus_; 67 : } 68 : 69 : template <size_t Dim> 70 : double IsotropicHomogeneous<Dim>::shear_modulus() const noexcept { 71 : return shear_modulus_; 72 : } 73 : 74 : template <size_t Dim> 75 : double IsotropicHomogeneous<Dim>::lame_parameter() const noexcept { 76 : return bulk_modulus_ - 2. * shear_modulus_ / 3.; 77 : } 78 : 79 : template <size_t Dim> 80 : double IsotropicHomogeneous<Dim>::youngs_modulus() const noexcept { 81 : return 9. * bulk_modulus_ * shear_modulus_ / 82 : (3. * bulk_modulus_ + shear_modulus_); 83 : } 84 : 85 : template <size_t Dim> 86 : double IsotropicHomogeneous<Dim>::poisson_ratio() const noexcept { 87 : return (3. * bulk_modulus_ - 2. * shear_modulus_) / 88 : (6. * bulk_modulus_ + 2. * shear_modulus_); 89 : } 90 : 91 : template <size_t Dim> 92 : void IsotropicHomogeneous<Dim>::pup(PUP::er& p) noexcept { 93 : p | bulk_modulus_; 94 : p | shear_modulus_; 95 : } 96 : 97 : template <size_t Dim> 98 0 : bool operator==(const IsotropicHomogeneous<Dim>& lhs, 99 : const IsotropicHomogeneous<Dim>& rhs) noexcept { 100 : return lhs.bulk_modulus() == rhs.bulk_modulus() and 101 : lhs.shear_modulus() == rhs.shear_modulus(); 102 : } 103 : template <size_t Dim> 104 0 : bool operator!=(const IsotropicHomogeneous<Dim>& lhs, 105 : const IsotropicHomogeneous<Dim>& rhs) noexcept { 106 : return not(lhs == rhs); 107 : } 108 : 109 : /// \cond 110 : #define DIM(data) BOOST_PP_TUPLE_ELEM(0, data) 111 : 112 : #define INSTANTIATE(_, data) \ 113 : template class IsotropicHomogeneous<DIM(data)>; \ 114 : template bool operator==( \ 115 : const IsotropicHomogeneous<DIM(data)>& lhs, \ 116 : const IsotropicHomogeneous<DIM(data)>& rhs) noexcept; \ 117 : template bool operator!=( \ 118 : const IsotropicHomogeneous<DIM(data)>& lhs, \ 119 : const IsotropicHomogeneous<DIM(data)>& rhs) noexcept; 120 : 121 : GENERATE_INSTANTIATIONS(INSTANTIATE, (2, 3)) 122 : 123 : #undef DIM 124 : #undef INSTANTIATE 125 : 126 : /// \endcond 127 : 128 : } // namespace Elasticity::ConstitutiveRelations