17 template <
typename T1,
typename T2,
int DIM1,
int DIM2>
23 "Case of mixed dimension by gradient not implemented");
27 double ave_tr_strain = 0;
30 for (
auto gg = 0; gg != nb_gauss_pts; ++gg) {
32 ave_tr_strain += t_w * t_grad(
i,
i);
36 ave_tr_strain /= (
DIM1 *
v);
41 template <
typename T1,
typename T2,
int DIM1,
int DIM2,
int DIM3>
49 "Case of mixed dimessnion by gradient not implemented");
55 t_strain(
i,
j) = (t_grad(
i,
j) || t_grad(
j,
i)) / 2;
56 double tr_strain = t_grad(
i,
i) /
DIM1;
61 t_strain(
i,
j) += (ave_tr_strain - tr_strain) *
t_kd(
i,
j);
68 return t_voight_strain;
87 const int nb_integration_pts,
double *w_ptr,
89 const auto nb_dofs = data.getFieldData().size();
90 const auto nb_bases = data.getN().size2();
92 storage.resize(nb_integration_pts, 6 * nb_dofs,
false);
103 auto get_ftensor2_symmetric = [&](
const int gg,
const int rr) {
108 auto calc_base = [&]() {
109 auto t_t2_diff = get_ftensor2_symmetric(0, 0);
110 for (
auto gg = 0; gg != nb_integration_pts; ++gg) {
111 auto t_diff = data.getFTensor1DiffN<DIM>(gg, 0);
112 for (
auto b = 0; b != nb_dofs / DIM; ++b) {
117 t_grad(N0,
J) = t_diff(
J);
118 t_t2_diff(
i,
j) = (t_grad(
i,
j) || t_grad(
j,
i)) / 2;
122 t_grad(N1,
J) = t_diff(
J);
123 t_t2_diff(
i,
j) = (t_grad(
i,
j) || t_grad(
j,
i)) / 2;
127 if constexpr (DIM == 3) {
128 t_grad(N2,
J) = t_diff(
J);
129 t_t2_diff(
i,
j) = (t_grad(
i,
j) || t_grad(
j,
i)) / 2;
136 return get_ftensor2_symmetric(0, 0);
140 auto calc_vol = [&](
auto &&t_t2_dff) {
141 std::vector<double> vol(nb_dofs, 0);
142 for (
auto gg = 0; gg != nb_integration_pts; ++gg) {
143 for (
auto b = 0; b != nb_dofs; ++b) {
144 vol[b] += w_ptr[gg] * t_t2_dff(
i,
i) / DIM;
149 for (
auto gg = 0; gg != nb_integration_pts; ++gg) {
152 for (
auto &
v : vol) {
159 auto make_b_bar = [&](
auto &&vol) {
160 auto t_t2_diff = get_ftensor2_symmetric(0, 0);
162 for (
auto gg = 0; gg != nb_integration_pts; ++gg) {
163 for (
auto b = 0; b != nb_dofs; ++b) {
164 const auto trace = t_t2_diff(
J,
J) / DIM;
169 return get_ftensor2_symmetric(0, 0);
172 return b_bar ? make_b_bar(calc_vol(calc_base())) : calc_base();
179 const int nb_integration_pts,
double *w_ptr,
188 const int nb_integration_pts,
double *w_ptr,
196 OpUpdate(boost::shared_ptr<CommonData> common_data_ptr);
205 OpUpdate::OpUpdate(boost::shared_ptr<CommonData> common_data_ptr)
208 commonDataPtr(common_data_ptr) {}
216 for (
int gg = 0; gg < nb_gauss_pts; gg++) {
218 auto cp_plastic_strain =
commonDataPtr->getPlasticStrain(gg);
219 auto cp_internal_variables =
commonDataPtr->getInternalVariables(gg);
220 const auto nb_internal_variables = cp_internal_variables.size();
221 auto plastic_strain =
224 &
commonDataPtr->internalVariablesPtr[gg * nb_internal_variables],
225 nb_internal_variables);
226 plastic_strain = cp_plastic_strain;
227 internal_variables = cp_internal_variables;
238 boost::shared_ptr<CommonData> common_data_ptr,
239 boost::shared_ptr<ClosestPointProjection> cp_ptr,
248 boost::shared_ptr<ClosestPointProjection>
cpPtr;
257 const int nb_internal_variables);
263 boost::shared_ptr<ClosestPointProjection> cp_ptr,
bool calc_lhs)
266 mField(m_field), commonDataPtr(common_data_ptr), cpPtr(cp_ptr),
275 CHKERR mField.get_moab().tag_get_handle(
276 "PLASTIC_STRAIN", def_length, MB_TYPE_DOUBLE, thPlasticStrain,
277 MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN, NULL);
278 CHKERR mField.get_moab().tag_get_handle(
279 "INTERNAL_VARIABLES", def_length, MB_TYPE_DOUBLE, thInternalVariables,
280 MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN, NULL);
287 const int nb_gauss_pts,
288 const int nb_internal_variables) {
293 rval = mField.get_moab().tag_get_by_ptr(
294 thPlasticStrain, &tet, 1,
295 (
const void **)&commonDataPtr->plasticStrainPtr,
296 &commonDataPtr->plasticStrainSize);
297 if (
rval != MB_SUCCESS ||
298 commonDataPtr->plasticStrainSize != 6 * nb_gauss_pts) {
299 v.resize(6 * nb_gauss_pts,
false);
302 tag_size[0] =
v.size();
303 void const *tag_data[] = {&
v[0]};
304 CHKERR mField.get_moab().tag_set_by_ptr(thPlasticStrain, &tet, 1,
306 CHKERR mField.get_moab().tag_get_by_ptr(
307 thPlasticStrain, &tet, 1,
308 (
const void **)&commonDataPtr->plasticStrainPtr,
309 &commonDataPtr->plasticStrainSize);
312 if (nb_internal_variables > 0) {
313 rval = mField.get_moab().tag_get_by_ptr(
314 thInternalVariables, &tet, 1,
315 (
const void **)&commonDataPtr->internalVariablesPtr,
316 &commonDataPtr->internalVariablesSize);
317 if (
rval != MB_SUCCESS || commonDataPtr->internalVariablesSize !=
318 nb_internal_variables * nb_gauss_pts) {
319 v.resize(nb_internal_variables * nb_gauss_pts,
false);
322 tag_size[0] =
v.size();
323 void const *tag_data[] = {&
v[0]};
324 CHKERR mField.get_moab().tag_set_by_ptr(thInternalVariables, &tet, 1,
326 CHKERR mField.get_moab().tag_get_by_ptr(
327 thInternalVariables, &tet, 1,
328 (
const void **)&commonDataPtr->internalVariablesPtr,
329 &commonDataPtr->internalVariablesSize);
341 int nb_gauss_pts = getGaussPts().size2();
343 int nb_internal_variables = cpPtr->nbInternalVariables;
344 auto tet = getNumeredEntFiniteElementPtr()->getEnt();
345 CHKERR setTagsData(tet, nb_gauss_pts, nb_internal_variables);
347 commonDataPtr->activeVariablesW.resize(
348 nb_gauss_pts, 12 + cpPtr->nbInternalVariables,
false);
349 commonDataPtr->gradientW.resize(nb_gauss_pts, 12 + cpPtr->nbInternalVariables,
351 commonDataPtr->materialTangentOperator.resize(36, nb_gauss_pts,
false);
352 commonDataPtr->deltaGamma.resize(nb_gauss_pts);
363 if (getFEMethod()->snes_ctx != SnesMethod::CTX_SNESNONE) {
364 CHKERR SNESGetLinearSolveIterations(getFEMethod()->snes, &iter);
369 commonDataPtr->bBar, nb_gauss_pts,
370 getFTensor2FromMat<DIM, DIM>(commonDataPtr->gradAtGaussPts),
371 getFTensor0IntegrationWeight());
374 auto t_grad = getFTensor2FromMat<DIM, DIM>(commonDataPtr->gradAtGaussPts);
377 getFTensor4DdgFromMat<3, 3, 1>(commonDataPtr->materialTangentOperator);
378 for (
auto gg = 0; gg != nb_gauss_pts; ++gg) {
382 12 + cpPtr->nbInternalVariables);
383 cpPtr->activeVariablesW.swap(tmp_active);
385 12 + cpPtr->nbInternalVariables);
386 cpPtr->gradientW.swap(tmp_gradient);
388 auto t_voigt_strain =
389 calcStrain(commonDataPtr->bBar, ave_tr_strain, t_grad,
390 getFTensor1FromPtr<6>(&(cpPtr->activeVariablesW[6])));
394 auto copy_plastic_strain_and_internal_variables = [&]() {
400 6, &commonDataPtr->plasticStrainPtr[gg * 6]));
402 nb_internal_variables,
403 ublas::shallow_array_adaptor<double>(
404 nb_internal_variables,
406 ->internalVariablesPtr[gg * nb_internal_variables]));
409 cpPtr->plasticStrain0.resize(6,
false);
410 noalias(cpPtr->plasticStrain0) = plastic_strain_tags;
411 cpPtr->internalVariables0.resize(nb_internal_variables,
false);
412 noalias(cpPtr->internalVariables0) = internal_variables_tags;
414 auto cp_plastic_strain = cpPtr->getPlasticStrain();
415 auto cp_internal_variables = cpPtr->getInternalVariables();
416 noalias(cp_plastic_strain) = plastic_strain_tags;
417 noalias(cp_internal_variables) = internal_variables_tags;
421 CHKERR copy_plastic_strain_and_internal_variables();
423 auto closest_point_projection = [&](
auto &recalculate_elastic_tangent) {
427 CHKERR cpPtr->setParams(
t, recalculate_elastic_tangent);
429 CHKERR cpPtr->playW_NoHessian();
430 CHKERR cpPtr->playY_NoGradient();
432 cpPtr->deltaGamma = 0;
433 if (iter > 0 && y > std::numeric_limits<double>::epsilon()) {
434 CHKERR cpPtr->solveClosetProjection();
436 commonDataPtr->deltaGamma[gg] = cpPtr->deltaGamma;
440 auto evaluate_consistent_tangent_matrix =
441 [&](
auto &recalculate_elastic_tangent) {
443 if (recalculate_elastic_tangent)
447 cpPtr->deltaGamma > std::numeric_limits<double>::epsilon()) {
449 CHKERR cpPtr->consistentTangent();
451 auto &
m = cpPtr->Cep;
456 &
m(0, 0), &
m(0, 1), &
m(0, 2), &
m(0, 3), &
m(0, 4), &
m(0, 5),
458 &
m(1, 0), &
m(1, 1), &
m(1, 2), &
m(1, 3), &
m(1, 4), &
m(1, 5),
460 &
m(2, 0), &
m(2, 1), &
m(2, 2), &
m(2, 3), &
m(2, 4), &
m(2, 5),
462 &
m(3, 0), &
m(3, 1), &
m(3, 2), &
m(3, 3), &
m(3, 4), &
m(3, 5),
464 &
m(4, 0), &
m(4, 1), &
m(4, 2), &
m(4, 3), &
m(4, 4), &
m(4, 5),
466 &
m(5, 0), &
m(5, 1), &
m(5, 2), &
m(5, 3), &
m(5, 4), &
m(5, 5)
471 t_voight_stress_op(
i,
j, Z) *
472 (t_voight_cep(Z, Y) * t_voight_stress_op(
k,
l, Y));
479 &
m(0, 0), &
m(0, 1), &
m(0, 2), &
m(0, 3), &
m(0, 4), &
m(0, 5),
481 &
m(1, 1), &
m(1, 2), &
m(1, 3), &
m(1, 4), &
m(1, 5),
483 &
m(2, 2), &
m(2, 3), &
m(2, 4), &
m(2, 5),
485 &
m(3, 3), &
m(3, 4), &
m(3, 5),
492 t_voight_stress_op(
i,
j, Z) *
493 (t_voight_cep(Z, Y) * t_voight_stress_op(
k,
l, Y));
501 bool recalculate_elastic_tangent = (getNinTheLoop() == 0) ?
true :
false;
502 CHKERR closest_point_projection(recalculate_elastic_tangent);
504 CHKERR evaluate_consistent_tangent_matrix(recalculate_elastic_tangent);
507 auto calcs_stress_matrix = [&]() {
510 commonDataPtr->stressMatrix.resize(6, commonDataPtr->gradientW.size1(),
512 auto t_stess = getFTensor2SymmetricFromMat<3>(commonDataPtr->stressMatrix);
513 auto t_voight_stress = commonDataPtr->getFTensor1StressAtGaussPts();
514 for (
auto gg = 0; gg != commonDataPtr->gradientW.size1(); ++gg) {
515 t_stess(
i,
j) = t_voight_stress_op(
i,
j, Z) * t_voight_stress(Z);
522 auto calcs_plastic_strain_matrix = [&]() {
525 commonDataPtr->plasticStrainMatrix.resize(
526 6, commonDataPtr->activeVariablesW.size1(),
false);
527 auto t_plastic_strain =
528 getFTensor2SymmetricFromMat<3>(commonDataPtr->plasticStrainMatrix);
529 auto t_voight_plastic_strain =
530 commonDataPtr->getFTensor1PlasticStrainAtGaussPts();
531 for (
auto gg = 0; gg != commonDataPtr->activeVariablesW.size1(); ++gg) {
532 t_plastic_strain(
i,
j) =
533 t_voight_strain_op(
i,
j, Z) * t_voight_plastic_strain(Z);
534 ++t_voight_plastic_strain;
540 CHKERR calcs_stress_matrix();
541 CHKERR calcs_plastic_strain_matrix();
549 boost::shared_ptr<ClosestPointProjection> cp_ptr,
bool calc_lhs) {
556 boost::shared_ptr<ClosestPointProjection> cp_ptr,
bool calc_lhs) {
563 std::string block_name,
564 boost::shared_ptr<CommonData> common_data_ptr,
565 boost::shared_ptr<ClosestPointProjection> cp_ptr) {
567 CHKERR cp_ptr->addMatBlockOps(m_field, pip, block_name, Sev::noisy);
569 getRawPtrOpCalculateStress<DIM>(m_field, common_data_ptr, cp_ptr,
false));
570 pip.push_back(
new OpUpdate(common_data_ptr));
577 std::string block_name,
578 boost::shared_ptr<CommonData> common_data_ptr,
579 boost::shared_ptr<ClosestPointProjection> cp_ptr) {
580 return opFactoryDomainUpdateImpl<3>(m_field, pip, block_name, common_data_ptr,
587 std::string block_name,
588 boost::shared_ptr<CommonData> common_data_ptr,
589 boost::shared_ptr<ClosestPointProjection> cp_ptr) {
590 return opFactoryDomainUpdateImpl<2>(m_field, pip, block_name, common_data_ptr,
601 TSUpdateImpl(std::string fe_name, boost::shared_ptr<FEMethod> fe_ptr);
610 boost::shared_ptr<FEMethod> fe_ptr)
611 : feName(fe_name), fePtr(fe_ptr) {}
631 boost::shared_ptr<FEMethod> fe_ptr) {
632 return boost::make_shared<TSUpdateImpl>(fe_name, fe_ptr);