v0.16.0
Loading...
Searching...
No Matches
MatGenericElasticSimpleDamage.hpp
Go to the documentation of this file.
1/**
2 * @file MatGenericElasticSimpleDamage.hpp
3 * @version 0.1
4 * @date 2026-04-19
5 *
6 * @copyright Copyright (c) 2026
7 *
8 */
9
10/*
11 @note: This is only example. This model is not real damage model, and do not
12 have any physical meaning. It is only for demonstration of how to implement
13 a simple damage model and update state variables.
14*/
15
16#ifndef ADOLC_GENERIC_ELASTIC_SIMPLE_DAMAGE_HPP
17#define ADOLC_GENERIC_ELASTIC_SIMPLE_DAMAGE_HPP
18
19#include <algorithm>
20#include <cmath>
21
23
25 double shear_modulus_G) {
26 constexpr auto size_symm = (SPACE_DIM * (SPACE_DIM + 1)) / 2;
27 auto mat_D_ptr = boost::make_shared<MatrixDouble>(1, size_symm * size_symm);
28
33
35
36 double A = 1.;
37 if (SPACE_DIM == 2) {
38 A = 2 * shear_modulus_G /
39 (bulk_modulus_K + (4. / 3.) * shear_modulus_G);
40 }
41
42 auto t_D = getFTensor4DdgFromMat<SPACE_DIM, SPACE_DIM, 0>(*mat_D_ptr);
43 t_D(i, j, k, l) = 2 * shear_modulus_G * ((t_kd(i, k) ^ t_kd(j, l)) / 4.) +
44 A * (bulk_modulus_K - (2. / 3.) * shear_modulus_G) *
45 t_kd(i, j) * t_kd(k, l);
46
47 return mat_D_ptr;
48}
49
50inline MoFEMErrorCode getSimpleDamageModuliFromBlock(
51 MoFEM::Interface &m_field, double &bulk_modulus_K,
52 double &shear_modulus_G) {
54
55 const auto blocks =
56 m_field.getInterface<MeshsetsManager>()->getCubitMeshsetPtr(
57 std::regex("MAT_ELASTIC.*"));
58
59 if (blocks.empty()) {
60 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
61 "No MAT_ELASTIC block found for simple damage example");
62 }
63 // Note: we expect only one block with elastic properties, but we read the first
64 std::vector<double> block_data;
65 CHKERR blocks.front()->getAttributes(block_data);
66 if (block_data.size() != 2) {
67 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
68 "Expected MAT_ELASTIC block with two attributes");
69 }
70
71 const double young_modulus = block_data[0];
72 const double poisson_ratio = block_data[1];
73 bulk_modulus_K = young_modulus / (3 * (1 - 2 * poisson_ratio));
75
77}
78
79inline MoFEMErrorCode configureSimpleDamage(
80 MoFEM::Interface &m_field,
81 boost::shared_ptr<MatOps::GenericElastic> physical_ptr) {
83
84 double max_damage = 0.999;
85 CHKERR PetscOptionsGetScalar(PETSC_NULLPTR, "", "-generic_max_damage",
86 &max_damage, PETSC_NULLPTR);
87 max_damage = std::min(0.999, std::max(0., max_damage));
88
89 double bulk_modulus_K = 0;
90 double shear_modulus_G = 0;
93 auto mat_D_ptr =
95
96 CHKERR physical_ptr->matOpsDataPtr->bindStateTag(m_field, "damage", 1);
97 CHKERR physical_ptr->matOpsDataPtr->bindStateTag(m_field, "F",
99 CHKERR physical_ptr->matOpsDataPtr->setupStateData();
100
101 physical_ptr->hookEvaluateVariable =
102 [mat_D_ptr](boost::shared_ptr<MatOps::MatOpsData> mat_ops_data_ptr,
103 int, EntityHandle ent, int gg) {
105
106 auto t_grad = getFTensor2FromPtr<SPACE_DIM, SPACE_DIM>(
107 mat_ops_data_ptr->getActiveDataPtr("F")->data().data());
108 auto t_P = getFTensor2FromPtr<SPACE_DIM, SPACE_DIM>(
109 mat_ops_data_ptr->getDependentDataPtr("P")->data().data());
110 auto t_D = getFTensor4DdgFromMat<SPACE_DIM, SPACE_DIM, 0>(*mat_D_ptr);
111 auto t_damage = getFTensor0FromPtr(
112 &(*mat_ops_data_ptr->getStateDataPtr("damage", ent, gg))(0, 0));
113
118
119 t_P(i, J) = (1. - t_damage) * t_D(i, J, k, L) * t_grad(k, L);
120
122 };
123
124 physical_ptr->hookEvaluateDerivatives =
125 [mat_D_ptr](boost::shared_ptr<MatOps::MatOpsData> mat_ops_data_ptr,
126 int, EntityHandle ent, int gg) {
128
129 auto t_dP = getFTensor4FromPtr<SPACE_DIM, SPACE_DIM, SPACE_DIM,
130 SPACE_DIM>(mat_ops_data_ptr
131 ->getDependentDerivativesDataPtr(
132 "P_dF")
133 ->data()
134 .data());
135 auto t_D = getFTensor4DdgFromMat<SPACE_DIM, SPACE_DIM, 0>(*mat_D_ptr);
136 auto t_damage = getFTensor0FromPtr(
137 &(*mat_ops_data_ptr->getStateDataPtr("damage", ent, gg))(0, 0));
138
143
144 t_dP(i, J, k, L) = (1. - t_damage) * t_D(i, J, k, L);
145
147 };
148
149 physical_ptr->hookUpdateState =
150 [max_damage](boost::shared_ptr<MatOps::MatOpsData> mat_ops_data_ptr,
151 int, EntityHandle ent, int gg) {
153
154 auto t_F = getFTensor2FromPtr<SPACE_DIM, SPACE_DIM>(
155 mat_ops_data_ptr->getActiveDataPtr("F")->data().data());
156 // state variables damage and F (for testing only)
157 auto damage_ptr = mat_ops_data_ptr->getStateDataPtr("damage", ent, gg);
158 auto t_damage = getFTensor0FromPtr(&(*damage_ptr)(0, 0));
159 auto F_state_ptr = mat_ops_data_ptr->getStateDataPtr("F", ent, gg);
160 auto t_F_state = getFTensor2FromPtr<SPACE_DIM, SPACE_DIM>(
161 &(*F_state_ptr)(0, 0));
162
165
166 const double grad_norm = std::sqrt(t_F(i, J) * t_F(i, J));
167 const double old_damage = t_damage;
168
169 t_damage = std::min(max_damage, std::max(old_damage, grad_norm));
170 t_F_state(i, J) = t_F(i, J);
171
173 };
174
176}
177
178} // namespace GenericElasticExamples
179
180#endif // ADOLC_GENERIC_ELASTIC_SIMPLE_DAMAGE_HPP
#define FTENSOR_INDEX(DIM, I)
constexpr int SPACE_DIM
Kronecker Delta class symmetric.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
double bulk_modulus_K
double shear_modulus_G
constexpr auto t_kd
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'J', DIM1 > J
Definition level_set.cpp:30
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
MoFEMErrorCode getSimpleDamageModuliFromBlock(MoFEM::Interface &m_field, double &bulk_modulus_K, double &shear_modulus_G)
auto makeSimpleDamageStiffness(double bulk_modulus_K, double shear_modulus_G)
MoFEMErrorCode configureSimpleDamage(MoFEM::Interface &m_field, boost::shared_ptr< MatOps::GenericElastic > physical_ptr)
constexpr AssemblyType A
Deprecated interface functions.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
double young_modulus
Young modulus.
Definition plastic.cpp:126
double poisson_ratio
Poisson ratio.
Definition plastic.cpp:127
constexpr auto size_symm
Definition plastic.cpp:42