Skip to content
Snippets Groups Projects
Commit a0dc1928 authored by webmanue's avatar webmanue
Browse files

allow parametrization of value- and real_type

- permits complex displacement gradients, stresses, strains, tangents
parent bc330451
No related branches found
No related tags found
No related merge requests found
...@@ -31,43 +31,44 @@ namespace materialmodels { ...@@ -31,43 +31,44 @@ namespace materialmodels {
* @brief A material model for linear elastic isotropic materials. * @brief A material model for linear elastic isotropic materials.
* @remark See https://en.wikipedia.org/wiki/Hooke%27s_law * @remark See https://en.wikipedia.org/wiki/Hooke%27s_law
*/ */
template <std::size_t Dimension_> template <std::size_t Dimension_, class ValueType_ = double,
class RealType_ = double>
class Hookean final class Hookean final
: public MaterialModelBase<std::size_t, double, Dimension_> { : public MaterialModelBase<std::size_t, ValueType_, RealType_, Dimension_> {
public: public:
/** /**
* @brief Constructs the material model using Young's modulus E and the * @brief Constructs the material model using Young's modulus E and the
* Poisson ratio nu. * Poisson ratio nu.
*/ */
explicit constexpr Hookean( explicit constexpr Hookean(
const typename Hookean::value_type &youngs_modulus, const typename Hookean::real_type &youngs_modulus,
const typename Hookean::value_type &poisson_ratio) noexcept const typename Hookean::real_type &poisson_ratio) noexcept
: lambda_(youngs_modulus * poisson_ratio / : lambda_(youngs_modulus * poisson_ratio /
(typename Hookean::value_type{1.} - (typename Hookean::real_type{1.} -
typename Hookean::value_type{2.} * poisson_ratio) / typename Hookean::real_type{2.} * poisson_ratio) /
(typename Hookean::value_type{1.} + poisson_ratio)), (typename Hookean::real_type{1.} + poisson_ratio)),
mu_(youngs_modulus / typename Hookean::value_type{2.} / mu_(youngs_modulus / typename Hookean::real_type{2.} /
(typename Hookean::value_type{1.} + poisson_ratio)) {} (typename Hookean::real_type{1.} + poisson_ratio)) {}
/** /**
* @brief Returns the first Lame constant. * @brief Returns the first Lame constant.
*/ */
constexpr typename Hookean::value_type lambda() const noexcept { constexpr typename Hookean::real_type lambda() const noexcept {
return lambda_; return lambda_;
} }
/** /**
* @brief Returns the second Lame constant. * @brief Returns the second Lame constant.
*/ */
constexpr typename Hookean::value_type mu() const noexcept { return mu_; } constexpr typename Hookean::real_type mu() const noexcept { return mu_; }
private: private:
typename Hookean::value_type lambda_; typename Hookean::real_type lambda_;
typename Hookean::value_type mu_; typename Hookean::real_type mu_;
}; };
template <std::size_t Dimension_> template <std::size_t Dimension_, class ValueType_, class RealType_>
struct ComputeEnergyTrait<Hookean<Dimension_>> { struct ComputeEnergyTrait<Hookean<Dimension_, ValueType_, RealType_>> {
template <class MaterialModel> template <class MaterialModel>
typename MaterialModel::Energy typename MaterialModel::Energy
operator()(const MaterialModel &model, operator()(const MaterialModel &model,
...@@ -76,15 +77,15 @@ struct ComputeEnergyTrait<Hookean<Dimension_>> { ...@@ -76,15 +77,15 @@ struct ComputeEnergyTrait<Hookean<Dimension_>> {
const typename MaterialModel::Time time) noexcept { const typename MaterialModel::Time time) noexcept {
const auto strain = compute_strain(model, id, gradient, time); const auto strain = compute_strain(model, id, gradient, time);
const auto stress = compute_stress(model, id, gradient, time); const auto stress = compute_stress(model, id, gradient, time);
return typename MaterialModel::value_type{0.5} * return typename MaterialModel::real_type{0.5} *
tensor::as_matrix_of_rows(&strain) tensor::as_matrix_of_rows(&strain)
.cwiseProduct(tensor::as_matrix_of_rows(&stress)) .cwiseProduct(tensor::as_matrix_of_rows(&stress))
.sum(); .sum();
} }
}; };
template <std::size_t Dimension_> template <std::size_t Dimension_, class ValueType_, class RealType_>
struct ComputeStrainTrait<Hookean<Dimension_>> { struct ComputeStrainTrait<Hookean<Dimension_, ValueType_, RealType_>> {
template <class MaterialModel> template <class MaterialModel>
typename MaterialModel::Strain typename MaterialModel::Strain
operator()(const MaterialModel &, const typename MaterialModel::size_type, operator()(const MaterialModel &, const typename MaterialModel::size_type,
...@@ -94,14 +95,14 @@ struct ComputeStrainTrait<Hookean<Dimension_>> { ...@@ -94,14 +95,14 @@ struct ComputeStrainTrait<Hookean<Dimension_>> {
typename MaterialModel::Strain result; typename MaterialModel::Strain result;
tensor::as_matrix_of_rows(&result) = tensor::as_matrix_of_rows(&result) =
typename MaterialModel::value_type{.5} * typename MaterialModel::real_type{.5} *
(gradient_matrix + gradient_matrix.transpose()); (gradient_matrix + gradient_matrix.transpose());
return result; return result;
} }
}; };
template <std::size_t Dimension_> template <std::size_t Dimension_, class ValueType_, class RealType_>
struct ComputeStressTrait<Hookean<Dimension_>> { struct ComputeStressTrait<Hookean<Dimension_, ValueType_, RealType_>> {
template <class MaterialModel> template <class MaterialModel>
typename MaterialModel::Stress typename MaterialModel::Stress
operator()(const MaterialModel &model, operator()(const MaterialModel &model,
...@@ -114,13 +115,13 @@ struct ComputeStressTrait<Hookean<Dimension_>> { ...@@ -114,13 +115,13 @@ struct ComputeStressTrait<Hookean<Dimension_>> {
typename MaterialModel::Stress result; typename MaterialModel::Stress result;
tensor::as_matrix_of_rows(&result) = tensor::as_matrix_of_rows(&result) =
model.lambda() * strain_matrix.trace() * strain_matrix.Identity() + model.lambda() * strain_matrix.trace() * strain_matrix.Identity() +
typename MaterialModel::value_type{2.} * model.mu() * strain_matrix; typename MaterialModel::real_type{2.} * model.mu() * strain_matrix;
return result; return result;
} }
}; };
template <std::size_t Dimension_> template <std::size_t Dimension_, class ValueType_, class RealType_>
struct ComputeTangentMatrixTrait<Hookean<Dimension_>> { struct ComputeTangentMatrixTrait<Hookean<Dimension_, ValueType_, RealType_>> {
template <class MaterialModel> template <class MaterialModel>
typename MaterialModel::TangentMatrix typename MaterialModel::TangentMatrix
operator()(const MaterialModel &model, operator()(const MaterialModel &model,
......
...@@ -21,11 +21,12 @@ namespace ae108 { ...@@ -21,11 +21,12 @@ namespace ae108 {
namespace elements { namespace elements {
namespace materialmodels { namespace materialmodels {
template <class SizeType_, class ValueType_, SizeType_ Dimension_, template <class SizeType_, class ValueType_, class RealType_,
SizeType_ DegreesOfFreedom_ = Dimension_> SizeType_ Dimension_, SizeType_ DegreesOfFreedom_ = Dimension_>
struct MaterialModelBase { struct MaterialModelBase {
using size_type = SizeType_; using size_type = SizeType_;
using value_type = ValueType_; using value_type = ValueType_;
using real_type = RealType_;
using Energy = value_type; using Energy = value_type;
using Time = value_type; using Time = value_type;
......
...@@ -30,7 +30,8 @@ namespace materialmodels { ...@@ -30,7 +30,8 @@ namespace materialmodels {
* defined. * defined.
*/ */
template <std::size_t Dimension_> template <std::size_t Dimension_>
struct Minimal final : MaterialModelBase<std::size_t, double, Dimension_> {}; struct Minimal final
: MaterialModelBase<std::size_t, double, double, Dimension_> {};
/** /**
* @brief Always returns 0. * @brief Always returns 0.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment