diff --git a/src/materials/material_linear_elastic_generic1.hh b/src/materials/material_linear_elastic_generic1.hh index 0680233..eb779f6 100644 --- a/src/materials/material_linear_elastic_generic1.hh +++ b/src/materials/material_linear_elastic_generic1.hh @@ -1,185 +1,185 @@ /** * @file material_linear_elastic_generic1.hh * * @author Till Junge * * @date 21 Sep 2018 * * @brief Implementation fo a generic linear elastic material that * stores the full elastic stiffness tensor. Convenient but not the * most efficient * * Copyright © 2018 Till Junge * * µSpectre 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, 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 Lesser General Public License * along with µSpectre; see the file COPYING. If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * * Boston, MA 02111-1307, USA. * * Additional permission under GNU GPL version 3 section 7 * * If you modify this Program, or any covered work, by linking or combining it * with proprietary FFT implementations or numerical libraries, containing parts * covered by the terms of those libraries' licenses, the licensors of this * Program grant you additional permission to convey the resulting work. */ #ifndef SRC_MATERIALS_MATERIAL_LINEAR_ELASTIC_GENERIC1_HH_ #define SRC_MATERIALS_MATERIAL_LINEAR_ELASTIC_GENERIC1_HH_ #include "common/common.hh" #include "common/T4_map_proxy.hh" #include "materials/material_muSpectre_base.hh" #include "common/tensor_algebra.hh" namespace muSpectre { /** * forward declaration */ template class MaterialLinearElasticGeneric1; /** * traits for use by MaterialMuSpectre for crtp */ template struct MaterialMuSpectre_traits> { //! global field collection using GFieldCollection_t = typename MaterialBase::GFieldCollection_t; //! expected map type for strain fields using StrainMap_t = MatrixFieldMap; //! expected map type for stress fields using StressMap_t = MatrixFieldMap; //! expected map type for tangent stiffness fields using TangentMap_t = T4MatrixFieldMap; //! declare what type of strain measure your law takes as input constexpr static auto strain_measure{StrainMeasure::GreenLagrange}; //! declare what type of stress measure your law yields as output constexpr static auto stress_measure{StressMeasure::PK2}; //! elasticity without internal variables using InternalVariables = std::tuple<>; }; /** * Linear elastic law defined by a full stiffness tensor. Very * generic, but not most efficient */ template class MaterialLinearElasticGeneric1 : public MaterialMuSpectre, DimS, DimM> { public: //! parent type using Parent = MaterialMuSpectre, DimS, DimM>; //! generic input tolerant to python input using CInput_t = Eigen::Ref, 0, Eigen::Stride>; //! Default constructor MaterialLinearElasticGeneric1() = delete; /** * Constructor by name and stiffness tensor. * * @param name unique material name * @param C_voigt elastic tensor in Voigt notation */ MaterialLinearElasticGeneric1(const std::string & name, const CInput_t & C_voigt); //! Copy constructor MaterialLinearElasticGeneric1(const MaterialLinearElasticGeneric1 & other) = delete; //! Move constructor MaterialLinearElasticGeneric1(MaterialLinearElasticGeneric1 && other) = delete; //! Destructor virtual ~MaterialLinearElasticGeneric1() = default; //! Copy assignment operator MaterialLinearElasticGeneric1 & operator=(const MaterialLinearElasticGeneric1 & other) = delete; //! Move assignment operator MaterialLinearElasticGeneric1 & operator=(MaterialLinearElasticGeneric1 && other) = delete; //! see //! http://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html EIGEN_MAKE_ALIGNED_OPERATOR_NEW; /** * evaluates second Piola-Kirchhoff stress given the Green-Lagrange * strain (or Cauchy stress if called with a small strain tensor) */ template inline decltype(auto) evaluate_stress(const Eigen::MatrixBase & E); /** * evaluates both second Piola-Kirchhoff stress and stiffness given * the Green-Lagrange strain (or Cauchy stress and stiffness if * called with a small strain tensor) */ template inline decltype(auto) evaluate_stress_tangent(const Eigen::MatrixBase & E); /** * return the empty internals tuple */ std::tuple<> & get_internals() { return this->internal_variables; } /** * return a reference to the stiffness tensor */ const T4Mat & get_C() const { return this->C; } protected: - T4Mat C{}; //! stiffness tensor + T4Mat C{}; //! stiffness tensor //! empty tuple std::tuple<> internal_variables{}; }; /* ---------------------------------------------------------------------- */ template template auto MaterialLinearElasticGeneric1::evaluate_stress( const Eigen::MatrixBase & E) -> decltype(auto) { static_assert(Derived::ColsAtCompileTime == DimM, "wrong input size"); static_assert(Derived::RowsAtCompileTime == DimM, "wrong input size"); return Matrices::tensmult(this->C, E); } /* ---------------------------------------------------------------------- */ template template auto MaterialLinearElasticGeneric1::evaluate_stress_tangent( const Eigen::MatrixBase & E) -> decltype(auto) { using Stress_t = decltype(this->evaluate_stress(E)); using Stiffness_t = Eigen::Map>; using Ret_t = std::tuple; return Ret_t{this->evaluate_stress(E), Stiffness_t(this->C.data())}; } } // namespace muSpectre #endif // SRC_MATERIALS_MATERIAL_LINEAR_ELASTIC_GENERIC1_HH_ diff --git a/src/materials/material_linear_elastic_generic2.hh b/src/materials/material_linear_elastic_generic2.hh index 74efca4..6690d08 100644 --- a/src/materials/material_linear_elastic_generic2.hh +++ b/src/materials/material_linear_elastic_generic2.hh @@ -1,202 +1,202 @@ /** * @file material_linear_elastic_generic2.hh * * @author Till Junge * * @date 20 Dec 2018 * * @brief implementation of a generic linear elastic law with eigenstrains * * Copyright © 2018 Till Junge * * µSpectre 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, 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 Lesser General Public License * along with µSpectre; see the file COPYING. If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * Additional permission under GNU GPL version 3 section 7 * * If you modify this Program, or any covered work, by linking or combining it * with proprietary FFT implementations or numerical libraries, containing parts * covered by the terms of those libraries' licenses, the licensors of this * Program grant you additional permission to convey the resulting work. */ #ifndef SRC_MATERIALS_MATERIAL_LINEAR_ELASTIC_GENERIC2_HH_ #define SRC_MATERIALS_MATERIAL_LINEAR_ELASTIC_GENERIC2_HH_ #include "material_linear_elastic_generic1.hh" namespace muSpectre { /** * forward declaration */ template class MaterialLinearElasticGeneric2; /** * traits for use by MaterialMuSpectre for crtp */ template struct MaterialMuSpectre_traits> { //! global field collection using GFieldCollection_t = typename MaterialBase::GFieldCollection_t; //! expected map type for strain fields using StrainMap_t = MatrixFieldMap; //! expected map type for stress fields using StressMap_t = MatrixFieldMap; //! expected map type for tangent stiffness fields using TangentMap_t = T4MatrixFieldMap; //! declare what type of strain measure your law takes as input constexpr static auto strain_measure{StrainMeasure::GreenLagrange}; //! declare what type of stress measure your law yields as output constexpr static auto stress_measure{StressMeasure::PK2}; //! local field_collections used for internals using LFieldColl_t = LocalFieldCollection; //! local strain type using LStrainMap_t = MatrixFieldMap; //! elasticity with eigenstrain using InternalVariables = std::tuple; }; /** * Implementation proper of the class */ template class MaterialLinearElasticGeneric2 : public MaterialMuSpectre, DimS, DimM> { //! parent type using Parent = MaterialMuSpectre, DimS, DimM>; //! underlying worker class using Law_t = MaterialLinearElasticGeneric1; //! generic input tolerant to python input using CInput_t = typename Law_t::CInput_t; //! reference to any type that casts to a matrix using StrainTensor = Eigen::Ref>; //! traits of this material using traits = MaterialMuSpectre_traits; //! Type of container used for storing eigenstrain using InternalVariables_t = typename traits::InternalVariables; public: //! Default constructor MaterialLinearElasticGeneric2() = delete; //! Construct by name and elastic stiffness tensor MaterialLinearElasticGeneric2(const std::string & name, const CInput_t & C_voigt); //! Copy constructor MaterialLinearElasticGeneric2(const MaterialLinearElasticGeneric2 & other) = delete; //! Move constructor MaterialLinearElasticGeneric2(MaterialLinearElasticGeneric2 && other) = default; //! Destructor virtual ~MaterialLinearElasticGeneric2() = default; //! Copy assignment operator MaterialLinearElasticGeneric2 & operator=(const MaterialLinearElasticGeneric2 & other) = delete; //! Move assignment operator MaterialLinearElasticGeneric2 & operator=(MaterialLinearElasticGeneric2 && other) = default; //! see //! http://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html EIGEN_MAKE_ALIGNED_OPERATOR_NEW; /** * evaluates second Piola-Kirchhoff stress given the Green-Lagrange * strain (or Cauchy stress if called with a small strain tensor) */ template inline decltype(auto) evaluate_stress(const Eigen::MatrixBase & E, const Eigen::MatrixBase & E_eig); /** * evaluates both second Piola-Kirchhoff stress and stiffness given * the Green-Lagrange strain (or Cauchy stress and stiffness if * called with a small strain tensor) */ template inline decltype(auto) evaluate_stress_tangent(const Eigen::MatrixBase & E, const Eigen::MatrixBase & E_eig); /** * returns tuple with only the eigenstrain field */ InternalVariables_t & get_internals() { return this->internal_variables; } /** * return a reference to the stiffness tensor */ const T4Mat & get_C() const { return this->worker.get_C(); } /** * overload add_pixel to write into eigenstrain */ void add_pixel(const Ccoord_t & pixel) final; /** * overload add_pixel to write into eigenstrain */ void add_pixel(const Ccoord_t & pixel, const StrainTensor & E_eig); protected: Law_t worker; //! underlying law to be evaluated //! storage for eigenstrain using Field_t = TensorField, Real, secondOrder, DimM>; Field_t & eigen_field; //!< field holding the eigen strain per pixel InternalVariables_t internal_variables; }; /* ---------------------------------------------------------------------- */ template template auto MaterialLinearElasticGeneric2::evaluate_stress( const Eigen::MatrixBase & E, const Eigen::MatrixBase & E_eig) -> decltype(auto) { return this->worker.evaluate_stress(E - E_eig); } /* ---------------------------------------------------------------------- */ template template auto MaterialLinearElasticGeneric2::evaluate_stress_tangent( const Eigen::MatrixBase & E, const Eigen::MatrixBase & E_eig) -> decltype(auto) { return this->worker.evaluate_stress_tangent(E - E_eig); } } // namespace muSpectre -#endif /* SRC_MATERIALS_MATERIAL_LINEAR_ELASTIC_GENERIC2_HH_ */ +#endif // SRC_MATERIALS_MATERIAL_LINEAR_ELASTIC_GENERIC2_HH_