v0.16.3
Loading...
Searching...
No Matches
ADOLCPlasticity.cpp
Go to the documentation of this file.
1/**
2 * \file ADOLCPlasticity.cpp
3 * \ingroup adoc_plasticity
4 * \brief Operators and data structures for ADOL-C plasticity
5 *
6 */
7
8#include <MoFEM.hpp>
9using namespace MoFEM;
10
11#include <ADOLCPlasticity.hpp>
12
13namespace ADOLCPlasticity {
14
16
17template <typename T1, typename T2, int DIM1, int DIM2>
18double calcAveStrain(bool b_bar, const int nb_gauss_pts,
21 if constexpr (DIM1 != DIM2)
23 "Case of mixed dimension by gradient not implemented");
24
25 FTensor::Index<'i', DIM1> i;
26 double ave_tr_strain = 0;
27 if (b_bar) {
28 double v = 0;
29 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
30 v += t_w;
31 ave_tr_strain += t_w * t_grad(i, i);
32 ++t_grad;
33 ++t_w;
34 }
35 ave_tr_strain /= (DIM1 * v);
36 }
37 return ave_tr_strain;
38}
39
40template <typename T1, typename T2, int DIM1, int DIM2, int DIM3>
42calcStrain(bool b_bar, double ave_tr_strain,
44 FTensor::Tensor1<T2, DIM3> &&t_voight_strain) {
45
46 if constexpr (DIM1 != DIM2)
48 "Case of mixed dimension by gradient not implemented");
49
50 FTensor::Index<'i', DIM1> i;
51 FTensor::Index<'j', DIM2> j;
52 FTensor::Index<'Z', DIM3> Z;
53 FTensor::Tensor2_symmetric<double, 3> t_strain{0., 0., 0., 0., 0., 0.};
54 t_strain(i, j) = (t_grad(i, j) || t_grad(j, i)) / 2;
55 double tr_strain = t_grad(i, i) / DIM1;
56 if (b_bar) {
57 FTensor::Index<'i', DIM1> i;
58 FTensor::Index<'j', DIM2> j;
60 t_strain(i, j) += (ave_tr_strain - tr_strain) * t_kd(i, j);
61 }
62 {
63 FTensor::Index<'i', 3> i;
64 FTensor::Index<'j', 3> j;
65 t_voight_strain(Z) = tStrainToVoightOp(i, j, Z) * t_strain(i, j);
66 }
67 return t_voight_strain;
68};
69
70template <typename T1, typename T2, int DIM1, int DIM3>
72calcStrain(bool b_bar, double ave_tr_strain,
74 FTensor::Tensor1<T2, DIM3> &&t_voight_strain) {
75
76 // TODO: implement this function to calculate b_bar strain
77
78 FTensor::Index<'Z', DIM3> Z;
79 {
80 FTensor::Index<'i', 3> i;
81 FTensor::Index<'j', 3> j;
82 t_voight_strain(Z) = tStrainToVoightOp(i, j, Z) * t_strain(i, j);
83 }
84 return t_voight_strain;
85};
86
87//! [BBar method]
88/**
89 * @brief Calculate base for B-bar method
90 *
91 * @tparam DIM Dimension of problem
92 * @param data access to base functions
93 * @param storage storage for base functions at integration points
94 * @param b_bar flag to sith on B-bar method
95 * @param nb_integration_pts number of integration points
96 * @param w_ptr integration weights
97 * @return FTensor::Tensor2_symmetric<FTensor::PackPtr<double *, 6>, 3>
98 */
99template <int DIM>
100auto getFTensor2SymmetricDiffBaseImpl(DataForcesAndSourcesCore::EntData &data,
101 MatrixDouble &storage, const bool b_bar,
102 const int nb_integration_pts,
103 double *w_ptr, FTensor::Number<DIM>) {
104 const auto nb_dofs = data.getFieldData().size();
105
106 storage.resize(nb_integration_pts, 6 * nb_dofs, false);
107
108 FTensor::Index<'I', DIM> I;
109 FTensor::Index<'J', DIM> J;
110 FTensor::Index<'i', 3> i;
111 FTensor::Index<'j', 3> j;
115
116 // get tensorial base
117 auto get_ftensor2_symmetric = [&](const int gg, const int rr) {
118 return getFTensor2SymmetricFromPtr<3>(&storage(gg, 6 * rr));
119 };
120
121 // calculate base
122 auto calc_base = [&]() {
123 auto t_t2_diff = get_ftensor2_symmetric(0, 0);
124 for (auto gg = 0; gg != nb_integration_pts; ++gg) {
125 auto t_diff = data.getFTensor1DiffN<DIM>(gg, 0);
126 for (auto b = 0; b != nb_dofs / DIM; ++b) {
128
129 t_grad(i, j) = 0;
130
131 t_grad(N0, J) = t_diff(J);
132 t_t2_diff(i, j) = (t_grad(i, j) || t_grad(j, i)) / 2;
133 ++t_t2_diff;
134
135 t_grad(i, j) = 0;
136 t_grad(N1, J) = t_diff(J);
137 t_t2_diff(i, j) = (t_grad(i, j) || t_grad(j, i)) / 2;
138 ++t_t2_diff;
139
140 t_grad(i, j) = 0;
141 if constexpr (DIM == 3) {
142 t_grad(N2, J) = t_diff(J);
143 t_t2_diff(i, j) = (t_grad(i, j) || t_grad(j, i)) / 2;
144 ++t_t2_diff;
145 }
146
147 ++t_diff;
148 }
149 }
150 };
151
152 // calculate volume average of trace
153 auto calc_vol = [&]() {
154 auto t_t2_dff = get_ftensor2_symmetric(0, 0);
155 std::vector<double> vol(nb_dofs, 0);
156 for (auto gg = 0; gg != nb_integration_pts; ++gg) {
157 for (auto b = 0; b != nb_dofs; ++b) {
158 vol[b] += w_ptr[gg] * t_t2_dff(i, i) / DIM;
159 ++t_t2_dff;
160 }
161 }
162 double sum = 0;
163 for (auto gg = 0; gg != nb_integration_pts; ++gg) {
164 sum += w_ptr[gg];
165 }
166 for (auto &v : vol) {
167 v /= sum;
168 }
169 return vol;
170 };
171
172 // modify base for B-bar method
173 auto make_b_bar = [&](auto &&vol) {
174 auto t_t2_diff = get_ftensor2_symmetric(0, 0);
176 for (auto gg = 0; gg != nb_integration_pts; ++gg) {
177 for (auto b = 0; b != nb_dofs; ++b) {
178 const auto trace = t_t2_diff(J, J) / DIM;
179 t_t2_diff(I, J) += (vol[b] - trace) * t_kd(I, J);
180 ++t_t2_diff;
181 }
182 }
183 };
184
185 calc_base();
186 if (b_bar) {
187 make_b_bar(calc_vol());
188 }
189
190 return get_ftensor2_symmetric(0, 0);
191};
192//! [BBar method]
193
194// specialization for 3d
196MakeB::getFTensor2SymmetricDiffBase(DataForcesAndSourcesCore::EntData &data,
197 MatrixDouble &storage, const bool b_bar,
198 const int nb_integration_pts, double *w_ptr,
201 data, storage, b_bar, nb_integration_pts, w_ptr, FTensor::Number<3>());
202}
203
204// specialization for 2da
206MakeB::getFTensor2SymmetricDiffBase(DataForcesAndSourcesCore::EntData &data,
207 MatrixDouble &storage, const bool b_bar,
208 const int nb_integration_pts, double *w_ptr,
211 data, storage, b_bar, nb_integration_pts, w_ptr, FTensor::Number<2>());
212}
213
215
216 OpUpdate(boost::shared_ptr<CommonData> common_data_ptr);
217
218 MoFEMErrorCode doWork(int side, EntityType type,
219 DataForcesAndSourcesCore::EntData &data);
220
221protected:
222 boost::shared_ptr<CommonData> commonDataPtr;
223};
224
225OpUpdate::OpUpdate(boost::shared_ptr<CommonData> common_data_ptr)
227 UserDataOperator::OPSPACE),
228 commonDataPtr(common_data_ptr) {}
229
231 DataForcesAndSourcesCore::EntData &data) {
233
234 int nb_gauss_pts = getGaussPts().size2();
235
236 for (int gg = 0; gg < nb_gauss_pts; gg++) {
237 if (commonDataPtr->deltaGamma[gg] > 0) {
238 auto cp_plastic_strain = commonDataPtr->getPlasticStrain(gg);
239 auto cp_internal_variables = commonDataPtr->getInternalVariables(gg);
240 const auto nb_internal_variables = cp_internal_variables.size();
241 auto plastic_strain =
242 getVectorAdaptor(&commonDataPtr->plasticStrainPtr[gg * 6], 6);
243 auto internal_variables = getVectorAdaptor(
244 &commonDataPtr->internalVariablesPtr[gg * nb_internal_variables],
245 nb_internal_variables);
246 plastic_strain = cp_plastic_strain;
247 internal_variables = cp_internal_variables;
248 }
249 }
250
252}
253
254template <int DIM, StrainType STRAIN>
256
258 boost::shared_ptr<CommonData> common_data_ptr,
259 boost::shared_ptr<ClosestPointProjection> cp_ptr,
260 bool calc_lhs);
261
262protected:
264 boost::shared_ptr<CommonData> commonDataPtr;
265 boost::shared_ptr<ClosestPointProjection> cpPtr;
267
270
272
273 MoFEMErrorCode setTagsData(const EntityHandle tet, const int nb_gauss_pts,
274 const int nb_internal_variables);
275};
276
277template <int DIM, StrainType STRAIN>
278struct OpCalculateStress : public OpCalculateStressImpl<DIM, STRAIN> {
279
280 using OpCalculateStressImpl<DIM, STRAIN>::OpCalculateStressImpl;
281
282 MoFEMErrorCode doWork(int side, EntityType type,
283 DataForcesAndSourcesCore::EntData &data) override;
284};
285template <int DIM>
287 : public OpCalculateStressImpl<DIM, LARGE_STRAIN> {
288
289 using OpCalculateStressImpl<DIM, LARGE_STRAIN>::OpCalculateStressImpl;
290
291 MoFEMErrorCode doWork(int side, EntityType type,
292 DataForcesAndSourcesCore::EntData &data) override;
293};
294
295template <int DIM>
297 : public OpCalculateStressImpl<DIM, SMALL_STRAIN> {
298
299 using OpCalculateStressImpl<DIM, SMALL_STRAIN>::OpCalculateStressImpl;
300
301 MoFEMErrorCode doWork(int side, EntityType type,
302 DataForcesAndSourcesCore::EntData &data) override;
303};
304
305template <int DIM, StrainType STRAIN>
307 MoFEM::Interface &m_field, boost::shared_ptr<CommonData> common_data_ptr,
308 boost::shared_ptr<ClosestPointProjection> cp_ptr, bool calc_lhs)
310 NOSPACE, UserDataOperator::OPSPACE),
311 mField(m_field), commonDataPtr(common_data_ptr), cpPtr(cp_ptr),
312 calcLhs(calc_lhs) {
313 CHK_THROW_MESSAGE(getTags(), "get tags");
314}
315
316template <int DIM, StrainType STRAIN>
319 int def_length = 0;
320 CHKERR mField.get_moab().tag_get_handle(
321 "PLASTIC_STRAIN", def_length, MB_TYPE_DOUBLE, thPlasticStrain,
322 MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN, NULL);
323 CHKERR mField.get_moab().tag_get_handle(
324 "INTERNAL_VARIABLES", def_length, MB_TYPE_DOUBLE, thInternalVariables,
325 MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_VARLEN, NULL);
327}
328
329template <int DIM, StrainType STRAIN>
331 const EntityHandle tet, const int nb_gauss_pts,
332 const int nb_internal_variables) {
334
336 {
337 rval = mField.get_moab().tag_get_by_ptr(
338 thPlasticStrain, &tet, 1,
339 (const void **)&commonDataPtr->plasticStrainPtr,
340 &commonDataPtr->plasticStrainSize);
341 if (rval != MB_SUCCESS ||
342 commonDataPtr->plasticStrainSize != 6 * nb_gauss_pts) {
343 v.resize(6 * nb_gauss_pts, false);
344 v.clear();
345 int tag_size[1];
346 tag_size[0] = v.size();
347 void const *tag_data[] = {&v[0]};
348 CHKERR mField.get_moab().tag_set_by_ptr(thPlasticStrain, &tet, 1,
349 tag_data, tag_size);
350 CHKERR mField.get_moab().tag_get_by_ptr(
351 thPlasticStrain, &tet, 1,
352 (const void **)&commonDataPtr->plasticStrainPtr,
353 &commonDataPtr->plasticStrainSize);
354 }
355 }
356 if (nb_internal_variables > 0) {
357 rval = mField.get_moab().tag_get_by_ptr(
358 thInternalVariables, &tet, 1,
359 (const void **)&commonDataPtr->internalVariablesPtr,
360 &commonDataPtr->internalVariablesSize);
361 if (rval != MB_SUCCESS || commonDataPtr->internalVariablesSize !=
362 nb_internal_variables * nb_gauss_pts) {
363 v.resize(nb_internal_variables * nb_gauss_pts, false);
364 v.clear();
365 int tag_size[1];
366 tag_size[0] = v.size();
367 void const *tag_data[] = {&v[0]};
368 CHKERR mField.get_moab().tag_set_by_ptr(thInternalVariables, &tet, 1,
369 tag_data, tag_size);
370 CHKERR mField.get_moab().tag_get_by_ptr(
371 thInternalVariables, &tet, 1,
372 (const void **)&commonDataPtr->internalVariablesPtr,
373 &commonDataPtr->internalVariablesSize);
374 }
375 }
377}
378
379template <int DIM>
381 int side, EntityType type, DataForcesAndSourcesCore::EntData &data) {
383
384 auto do_work_impl = [this](auto commonDataPtr, auto cpPtr) {
386
387 int nb_gauss_pts = this->getGaussPts().size2();
388
389 int nb_internal_variables = cpPtr->nbInternalVariables;
390 auto tet = this->getNumeredEntFiniteElementPtr()->getEnt();
391 CHKERR this->setTagsData(tet, nb_gauss_pts, nb_internal_variables);
392
393 commonDataPtr->activeVariablesW.resize(
394 nb_gauss_pts, 12 + cpPtr->nbInternalVariables, false);
395 commonDataPtr->gradientW.resize(nb_gauss_pts,
396 12 + cpPtr->nbInternalVariables, false);
397 commonDataPtr->deltaGamma.resize(nb_gauss_pts);
398
399 FTENSOR_INDEX(3, i);
400 FTENSOR_INDEX(3, j);
401 FTENSOR_INDEX(3, k);
402 FTENSOR_INDEX(3, l);
403 FTENSOR_INDEX(6, Z);
404 FTENSOR_INDEX(6, Y);
405
407 auto get_Cep =
409 commonDataPtr->materialTangentOperator, nb_gauss_pts);
410
411 // Code uses trial stress, until first solve of linear system of equations
412 int iter = 1;
413 if (this->getFEMethod()->snes_ctx != SnesMethod::CTX_SNESNONE) {
414 CHKERR SNESGetLinearSolveIterations(this->getFEMethod()->snes, &iter);
415 }
416
417 double ave_tr_strain = 0;
418 auto t_voight_stress_op = voight_to_stress_op();
419 auto t_grad =
420 getFTensor2SymmetricFromMat<DIM>(commonDataPtr->gradAtGaussPts);
421 auto t_Cep = get_Cep();
422
423 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
424
425 auto tmp_active =
426 getVectorAdaptor(&(commonDataPtr->activeVariablesW(gg, 0)),
427 12 + cpPtr->nbInternalVariables);
428 cpPtr->activeVariablesW.swap(tmp_active);
429 auto tmp_gradient = getVectorAdaptor(&(commonDataPtr->gradientW(gg, 0)),
430 12 + cpPtr->nbInternalVariables);
431 this->cpPtr->gradientW.swap(tmp_gradient);
432
433 auto t_voigt_strain =
434 calcStrain(commonDataPtr->bBar, ave_tr_strain, t_grad,
435 getFTensor1FromPtr<6>(&(cpPtr->activeVariablesW[6])));
436 ++t_grad;
437
438 // Copy plastic strains and internal variables from tags
439 auto copy_plastic_strain_and_internal_variables = [&]() {
441
442 // Get data stored on Tags
443 VectorAdaptor plastic_strain_tags =
444 VectorAdaptor(6, ublas::shallow_array_adaptor<double>(
445 6, &commonDataPtr->plasticStrainPtr[gg * 6]));
446 VectorAdaptor internal_variables_tags = VectorAdaptor(
447 nb_internal_variables,
448 ublas::shallow_array_adaptor<double>(
449 nb_internal_variables,
450 &commonDataPtr
451 ->internalVariablesPtr[gg * nb_internal_variables]));
452
453 // Set values to closest point projection
454 cpPtr->plasticStrain0.resize(6, false);
455 noalias(cpPtr->plasticStrain0) = plastic_strain_tags;
456 cpPtr->internalVariables0.resize(nb_internal_variables, false);
457 noalias(cpPtr->internalVariables0) = internal_variables_tags;
458
459 auto cp_plastic_strain = cpPtr->getPlasticStrain();
460 auto cp_internal_variables = cpPtr->getInternalVariables();
461 noalias(cp_plastic_strain) = plastic_strain_tags;
462 noalias(cp_internal_variables) = internal_variables_tags;
464 };
465
466 CHKERR copy_plastic_strain_and_internal_variables();
467
468 auto closest_point_projection = [&](auto &recalculate_elastic_tangent) {
472 CHKERR cpPtr->setParams(t, recalculate_elastic_tangent);
473 }
474 CHKERR cpPtr->playW_NoHessian();
475 CHKERR cpPtr->playY_NoGradient();
476 double y = cpPtr->y;
477 cpPtr->deltaGamma = 0; // zero lagrange multiplier
478 if (iter > 0 && y > std::numeric_limits<double>::epsilon()) {
479 CHKERR cpPtr->solveClosestProjection();
480 }
481 commonDataPtr->deltaGamma[gg] = cpPtr->deltaGamma;
483 };
484
485 auto evaluate_consistent_tangent_matrix =
486 [&](auto &recalculate_elastic_tangent) {
488 if (recalculate_elastic_tangent)
489 CHKERR cpPtr->playW();
490
491 if (iter > 0 &&
492 cpPtr->deltaGamma > std::numeric_limits<double>::epsilon()) {
493
494 CHKERR cpPtr->consistentTangent();
495
496 auto &m = cpPtr->Cep;
497 // for generic case of non-associated plasticity consistent
498 // tangent matrix is non-symmetric
499 auto t_voight_cep =
501 &m(0, 0), &m(0, 1), &m(0, 2), &m(0, 3), &m(0, 4),
502 &m(0, 5),
503
504 &m(1, 0), &m(1, 1), &m(1, 2), &m(1, 3), &m(1, 4),
505 &m(1, 5),
506
507 &m(2, 0), &m(2, 1), &m(2, 2), &m(2, 3), &m(2, 4),
508 &m(2, 5),
509
510 &m(3, 0), &m(3, 1), &m(3, 2), &m(3, 3), &m(3, 4),
511 &m(3, 5),
512
513 &m(4, 0), &m(4, 1), &m(4, 2), &m(4, 3), &m(4, 4),
514 &m(4, 5),
515
516 &m(5, 0), &m(5, 1), &m(5, 2), &m(5, 3), &m(5, 4), &m(5, 5)
517
518 );
519
520 FTENSOR_INDEX(DIM, i);
521 FTENSOR_INDEX(DIM, j);
522 FTENSOR_INDEX(DIM, k);
523 FTENSOR_INDEX(DIM, l);
524
525 t_Cep(i, j, k, l) =
526 t_voight_stress_op(i, j, Z) *
527 (t_voight_cep(Z, Y) * t_voight_stress_op(k, l, Y));
528
529 } else {
530
531 auto &m = cpPtr->C;
532 auto t_voight_cep =
534 &m(0, 0), &m(0, 1), &m(0, 2), &m(0, 3), &m(0, 4),
535 &m(0, 5),
536
537 &m(1, 1), &m(1, 2), &m(1, 3), &m(1, 4), &m(1, 5),
538
539 &m(2, 2), &m(2, 3), &m(2, 4), &m(2, 5),
540
541 &m(3, 3), &m(3, 4), &m(3, 5),
542
543 &m(4, 4), &m(4, 5),
544
545 &m(5, 5));
546
547 FTENSOR_INDEX(DIM, i);
548 FTENSOR_INDEX(DIM, j);
549 FTENSOR_INDEX(DIM, k);
550 FTENSOR_INDEX(DIM, l);
551
552 t_Cep(i, j, k, l) =
553 t_voight_stress_op(i, j, Z) *
554 (t_voight_cep(Z, Y) * t_voight_stress_op(k, l, Y));
555 }
556
557 ++t_Cep;
559 };
560
561 // Always recalculate elastic tangent if first element
562 bool recalculate_elastic_tangent =
563 (this->getNinTheLoop() == 0) ? true : false;
564 CHKERR closest_point_projection(recalculate_elastic_tangent);
565 // always calculate consistent tangent matrix for large strain
566 CHKERR evaluate_consistent_tangent_matrix(recalculate_elastic_tangent);
567 }
568
569 auto calcs_stress_matrix = [&]() {
571 auto t_voight_stress_op = voight_to_stress_op();
572
573 auto get_stress =
575 DL>::size(commonDataPtr->stressMatrix, nb_gauss_pts);
576 auto t_stess = get_stress();
577 auto t_voight_stress = commonDataPtr->getFTensor1StressAtGaussPts();
578 for (auto gg = 0; gg != commonDataPtr->gradientW.size1(); ++gg) {
579 FTENSOR_INDEX(DIM, i);
580 FTENSOR_INDEX(DIM, j);
581 FTENSOR_INDEX(DIM, k);
582 FTENSOR_INDEX(DIM, l);
583
584 t_stess(i, j) = t_voight_stress_op(i, j, Z) * t_voight_stress(Z);
585 ++t_voight_stress;
586 ++t_stess;
587 }
589 };
590
591 auto calcs_plastic_strain_matrix = [&]() {
593 auto t_voight_strain_op = voight_to_stress_op();
594 commonDataPtr->plasticStrainMatrix.resize(
595 commonDataPtr->activeVariablesW.size1(), 6, false);
596 auto t_plastic_strain =
597 getFTensor2SymmetricFromMat<3>(commonDataPtr->plasticStrainMatrix);
598 auto t_voight_plastic_strain =
599 commonDataPtr->getFTensor1PlasticStrainAtGaussPts();
600 for (auto gg = 0; gg != commonDataPtr->activeVariablesW.size1(); ++gg) {
601 t_plastic_strain(i, j) =
602 t_voight_strain_op(i, j, Z) * t_voight_plastic_strain(Z);
603 ++t_voight_plastic_strain;
604 ++t_plastic_strain;
605 }
607 };
608
609 CHKERR calcs_stress_matrix();
610 CHKERR calcs_plastic_strain_matrix();
612 };
613
614 CHKERR do_work_impl(this->commonDataPtr, this->cpPtr);
615
617}
618
619template <int DIM>
621 int side, EntityType type, DataForcesAndSourcesCore::EntData &data) {
623
624 auto do_work_impl = [this](auto commonDataPtr, auto cpPtr) {
626
627 int nb_gauss_pts = this->getGaussPts().size2();
628
629 int nb_internal_variables = cpPtr->nbInternalVariables;
630 auto tet = this->getNumeredEntFiniteElementPtr()->getEnt();
631 CHKERR this->setTagsData(tet, nb_gauss_pts, nb_internal_variables);
632
633 commonDataPtr->activeVariablesW.resize(
634 nb_gauss_pts, 12 + cpPtr->nbInternalVariables, false);
635 commonDataPtr->gradientW.resize(nb_gauss_pts,
636 12 + cpPtr->nbInternalVariables, false);
637 commonDataPtr->materialTangentOperator.resize(nb_gauss_pts, 36, false);
638 commonDataPtr->deltaGamma.resize(nb_gauss_pts);
639
640 FTensor::Index<'i', 3> i;
641 FTensor::Index<'j', 3> j;
642 FTensor::Index<'k', 3> k;
643 FTensor::Index<'l', 3> l;
644 FTensor::Index<'Z', 6> Z;
645 FTensor::Index<'Y', 6> Y;
646
647 // Code uses trial stress, until first solve of linear system of equations
648 int iter = 1;
649 if (this->getFEMethod()->snes_ctx != SnesMethod::CTX_SNESNONE) {
650 CHKERR SNESGetLinearSolveIterations(this->getFEMethod()->snes, &iter);
651 }
652
653 // b-bar
654 auto ave_tr_strain = calcAveStrain(
655 this->commonDataPtr->bBar, nb_gauss_pts,
656 getFTensor2FromMat<DIM, DIM>(commonDataPtr->gradAtGaussPts),
657 this->getFTensor0IntegrationWeight());
658
659 auto t_voight_stress_op = voight_to_stress_op();
660
661 auto t_grad = getFTensor2FromMat<DIM, DIM>(commonDataPtr->gradAtGaussPts);
662
663 auto t_Cep = getFTensor4DdgFromMat<3, 3>(
664 this->commonDataPtr->materialTangentOperator);
665 for (auto gg = 0; gg != nb_gauss_pts; ++gg) {
666
667 auto tmp_active =
668 getVectorAdaptor(&(commonDataPtr->activeVariablesW(gg, 0)),
669 12 + cpPtr->nbInternalVariables);
670 cpPtr->activeVariablesW.swap(tmp_active);
671 auto tmp_gradient = getVectorAdaptor(&(commonDataPtr->gradientW(gg, 0)),
672 12 + cpPtr->nbInternalVariables);
673 cpPtr->gradientW.swap(tmp_gradient);
674
675 auto t_voigt_strain =
676 calcStrain(commonDataPtr->bBar, ave_tr_strain, t_grad,
677 getFTensor1FromPtr<6>(&(cpPtr->activeVariablesW[6])));
678 ++t_grad;
679
680 // Copy plastic strains and internal variables from tags
681 auto copy_plastic_strain_and_internal_variables = [&]() {
683
684 // Get data stored on Tags
685 VectorAdaptor plastic_strain_tags =
686 VectorAdaptor(6, ublas::shallow_array_adaptor<double>(
687 6, &commonDataPtr->plasticStrainPtr[gg * 6]));
688 VectorAdaptor internal_variables_tags = VectorAdaptor(
689 nb_internal_variables,
690 ublas::shallow_array_adaptor<double>(
691 nb_internal_variables,
692 &commonDataPtr
693 ->internalVariablesPtr[gg * nb_internal_variables]));
694
695 // Set values to closest point projection
696 cpPtr->plasticStrain0.resize(6, false);
697 noalias(cpPtr->plasticStrain0) = plastic_strain_tags;
698 cpPtr->internalVariables0.resize(nb_internal_variables, false);
699 noalias(cpPtr->internalVariables0) = internal_variables_tags;
700
701 auto cp_plastic_strain = cpPtr->getPlasticStrain();
702 auto cp_internal_variables = cpPtr->getInternalVariables();
703 noalias(cp_plastic_strain) = plastic_strain_tags;
704 noalias(cp_internal_variables) = internal_variables_tags;
706 };
707
708 CHKERR copy_plastic_strain_and_internal_variables();
709
710 auto closest_point_projection = [&](auto &recalculate_elastic_tangent) {
714 CHKERR cpPtr->setParams(t, recalculate_elastic_tangent);
715 }
716 CHKERR cpPtr->playW_NoHessian();
717 CHKERR cpPtr->playY_NoGradient();
718 double y = cpPtr->y;
719 cpPtr->deltaGamma = 0; // zero lagrange multiplier
720 if (iter > 0 && y > std::numeric_limits<double>::epsilon()) {
721 CHKERR cpPtr->solveClosestProjection();
722 }
723 commonDataPtr->deltaGamma[gg] = cpPtr->deltaGamma;
725 };
726
727 auto evaluate_consistent_tangent_matrix =
728 [&](auto &recalculate_elastic_tangent) {
730 if (recalculate_elastic_tangent)
731 CHKERR cpPtr->playW();
732
733 if (iter > 0 &&
734 cpPtr->deltaGamma > std::numeric_limits<double>::epsilon()) {
735
736 CHKERR cpPtr->consistentTangent();
737
738 auto &m = cpPtr->Cep;
739 // for generic case of non-associated plasticity consistent
740 // tangent matrix is non-symmetric
741 auto t_voight_cep =
743 &m(0, 0), &m(0, 1), &m(0, 2), &m(0, 3), &m(0, 4),
744 &m(0, 5),
745
746 &m(1, 0), &m(1, 1), &m(1, 2), &m(1, 3), &m(1, 4),
747 &m(1, 5),
748
749 &m(2, 0), &m(2, 1), &m(2, 2), &m(2, 3), &m(2, 4),
750 &m(2, 5),
751
752 &m(3, 0), &m(3, 1), &m(3, 2), &m(3, 3), &m(3, 4),
753 &m(3, 5),
754
755 &m(4, 0), &m(4, 1), &m(4, 2), &m(4, 3), &m(4, 4),
756 &m(4, 5),
757
758 &m(5, 0), &m(5, 1), &m(5, 2), &m(5, 3), &m(5, 4), &m(5, 5)
759
760 );
761
762 t_Cep(i, j, k, l) =
763 t_voight_stress_op(i, j, Z) *
764 (t_voight_cep(Z, Y) * t_voight_stress_op(k, l, Y));
765
766 } else {
767
768 auto &m = cpPtr->C;
769 auto t_voight_cep =
771 &m(0, 0), &m(0, 1), &m(0, 2), &m(0, 3), &m(0, 4),
772 &m(0, 5),
773
774 &m(1, 1), &m(1, 2), &m(1, 3), &m(1, 4), &m(1, 5),
775
776 &m(2, 2), &m(2, 3), &m(2, 4), &m(2, 5),
777
778 &m(3, 3), &m(3, 4), &m(3, 5),
779
780 &m(4, 4), &m(4, 5),
781
782 &m(5, 5));
783
784 t_Cep(i, j, k, l) =
785 t_voight_stress_op(i, j, Z) *
786 (t_voight_cep(Z, Y) * t_voight_stress_op(k, l, Y));
787 }
788
789 ++t_Cep;
791 };
792
793 // Always recalculate elastic tangent if first element
794 bool recalculate_elastic_tangent =
795 (this->getNinTheLoop() == 0) ? true : false;
796 CHKERR closest_point_projection(recalculate_elastic_tangent);
797 if (this->calcLhs)
798 CHKERR evaluate_consistent_tangent_matrix(recalculate_elastic_tangent);
799 }
800
801 auto calcs_stress_matrix = [&]() {
803 auto t_voight_stress_op = voight_to_stress_op();
804 commonDataPtr->stressMatrix.resize(commonDataPtr->gradientW.size1(), 6,
805 false);
806 auto t_stess =
807 getFTensor2SymmetricFromMat<3>(commonDataPtr->stressMatrix);
808 auto t_voight_stress = commonDataPtr->getFTensor1StressAtGaussPts();
809 for (auto gg = 0; gg != commonDataPtr->gradientW.size1(); ++gg) {
810 t_stess(i, j) = t_voight_stress_op(i, j, Z) * t_voight_stress(Z);
811 ++t_voight_stress;
812 ++t_stess;
813 }
815 };
816
817 auto calcs_plastic_strain_matrix = [&]() {
819 auto t_voight_strain_op = voight_to_stress_op();
820 commonDataPtr->plasticStrainMatrix.resize(
821 commonDataPtr->activeVariablesW.size1(), 6, false);
822 auto t_plastic_strain =
823 getFTensor2SymmetricFromMat<3>(commonDataPtr->plasticStrainMatrix);
824 auto t_voight_plastic_strain =
825 commonDataPtr->getFTensor1PlasticStrainAtGaussPts();
826 for (auto gg = 0; gg != commonDataPtr->activeVariablesW.size1(); ++gg) {
827 t_plastic_strain(i, j) =
828 t_voight_strain_op(i, j, Z) * t_voight_plastic_strain(Z);
829 ++t_voight_plastic_strain;
830 ++t_plastic_strain;
831 }
833 };
834
835 CHKERR calcs_stress_matrix();
836 CHKERR calcs_plastic_strain_matrix();
838 };
839
840 CHKERR do_work_impl(this->commonDataPtr, this->cpPtr);
841
843}
844
845template <>
848 MoFEM::Interface &m_field, boost::shared_ptr<CommonData> common_data_ptr,
849 boost::shared_ptr<ClosestPointProjection> cp_ptr, bool calc_lhs) {
850 return new OpCalculateStress<3, LARGE_STRAIN>(m_field, common_data_ptr,
851 cp_ptr, calc_lhs);
852}
853
854template <>
857 MoFEM::Interface &m_field, boost::shared_ptr<CommonData> common_data_ptr,
858 boost::shared_ptr<ClosestPointProjection> cp_ptr, bool calc_lhs) {
859 return new OpCalculateStress<3, SMALL_STRAIN>(m_field, common_data_ptr,
860 cp_ptr, calc_lhs);
861}
862
863template <>
866 MoFEM::Interface &m_field, boost::shared_ptr<CommonData> common_data_ptr,
867 boost::shared_ptr<ClosestPointProjection> cp_ptr, bool calc_lhs) {
868 return new OpCalculateStress<2, LARGE_STRAIN>(m_field, common_data_ptr,
869 cp_ptr, calc_lhs);
870}
871
872template <>
875 MoFEM::Interface &m_field, boost::shared_ptr<CommonData> common_data_ptr,
876 boost::shared_ptr<ClosestPointProjection> cp_ptr, bool calc_lhs) {
877 return new OpCalculateStress<2, SMALL_STRAIN>(m_field, common_data_ptr,
878 cp_ptr, calc_lhs);
879}
880
881template <int DIM>
884 std::string block_name,
885 boost::shared_ptr<CommonData> common_data_ptr,
886 boost::shared_ptr<ClosestPointProjection> cp_ptr) {
888 pip.push_back(new OpUpdate(common_data_ptr));
890};
891
892template <>
895 std::string block_name,
896 boost::shared_ptr<CommonData> common_data_ptr,
897 boost::shared_ptr<ClosestPointProjection> cp_ptr) {
898 return opFactoryDomainUpdateImpl<3>(m_field, pip, block_name, common_data_ptr,
899 cp_ptr);
900};
901
902template <>
905 std::string block_name,
906 boost::shared_ptr<CommonData> common_data_ptr,
907 boost::shared_ptr<ClosestPointProjection> cp_ptr) {
908 return opFactoryDomainUpdateImpl<2>(m_field, pip, block_name, common_data_ptr,
909 cp_ptr);
910};
911
912//! [TSUpdateImpl]
913/**
914 * @brief TS update history variables
915 */
916struct TSUpdateImpl : public TSUpdate {
917
918 TSUpdateImpl(std::string fe_name, boost::shared_ptr<FEMethod> fe_ptr);
920
921private:
922 boost::shared_ptr<FEMethod> fePtr;
923 const std::string feName;
924};
925
926TSUpdateImpl::TSUpdateImpl(std::string fe_name,
927 boost::shared_ptr<FEMethod> fe_ptr)
928 : feName(fe_name), fePtr(fe_ptr) {}
929
932 DM dm;
933 CHKERR TSGetDM(ts, &dm);
934 // This is where update is preformed. Element list is iterated and on each
935 // element pipeline accessed throng fePtr is executed.
938}
939
940/**
941 * @brief Create test update object
942 *
943 * @param fe_name
944 * @param fe_ptr
945 * @return boost::shared_ptr<TSUpdate>
946 */
947boost::shared_ptr<TSUpdate> createTSUpdate(std::string fe_name,
948 boost::shared_ptr<FEMethod> fe_ptr) {
949 return boost::make_shared<TSUpdateImpl>(fe_name, fe_ptr);
950}
951//! [TSUpdateImpl]
952
953} // namespace ADOLCPlasticity
MoFEM::Interface & mField
std::vector< int > size
Vec t
Removal: the ring edge.
std::string type
#define FTENSOR_INDEX(DIM, I)
Kronecker Delta class symmetric.
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
@ NOSPACE
Definition definitions.h:83
#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 trace(FTensor::Tensor2< T, 2, 2 > &t_stress)
constexpr auto t_kd
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition DMMoFEM.cpp:662
FTensor::Index< 'i', SPACE_DIM > i
const double v
phase velocity of light in medium (cm/ns)
constexpr int DIM2
Definition level_set.cpp:22
FTensor::Index< 'J', DIM1 > J
Definition level_set.cpp:30
constexpr int DIM1
Definition level_set.cpp:21
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
ForcesAndSourcesCore::UserDataOperator * getRawPtrOpCalculateStress< 3, SMALL_STRAIN >(MoFEM::Interface &m_field, boost::shared_ptr< CommonData > common_data_ptr, boost::shared_ptr< ClosestPointProjection > cp_ptr, bool calc_lhs)
ForcesAndSourcesCore::UserDataOperator * getRawPtrOpCalculateStress< 2, SMALL_STRAIN >(MoFEM::Interface &m_field, boost::shared_ptr< CommonData > common_data_ptr, boost::shared_ptr< ClosestPointProjection > cp_ptr, bool calc_lhs)
FTensor::Dg< double, 3, 6 > strain_to_voight_op()
Op convert strain tensor to Vight strain vector.
FTensor::Dg< double, 3, 6 > voight_to_stress_op()
Op convert Vight stress vector to stress tensor.
auto getFTensor2SymmetricDiffBaseImpl(DataForcesAndSourcesCore::EntData &data, MatrixDouble &storage, const bool b_bar, const int nb_integration_pts, double *w_ptr, FTensor::Number< DIM >)
[BBar method]
MoFEMErrorCode opFactoryDomainUpdate< 2 >(MoFEM::Interface &m_field, Pip &pip, std::string block_name, boost::shared_ptr< CommonData > common_data_ptr, boost::shared_ptr< ClosestPointProjection > cp_ptr)
Push operators to update history variables.
static FTensor::Dg< double, 3, 6 > tStrainToVoightOp
double calcAveStrain(bool b_bar, const int nb_gauss_pts, FTensor::Tensor2< T1, DIM1, DIM2 > &&t_grad, FTensor::Tensor0< T2 > &&t_w)
MoFEMErrorCode opFactoryDomainUpdateImpl(MoFEM::Interface &m_field, Pip &pip, std::string block_name, boost::shared_ptr< CommonData > common_data_ptr, boost::shared_ptr< ClosestPointProjection > cp_ptr)
FTensor::Tensor1< T2, DIM3 > calcStrain(bool b_bar, double ave_tr_strain, FTensor::Tensor2< T1, DIM1, DIM2 > &t_grad, FTensor::Tensor1< T2, DIM3 > &&t_voight_strain)
boost::ptr_deque< ForcesAndSourcesCore::UserDataOperator > Pip
boost::shared_ptr< TSUpdate > createTSUpdate(std::string fe_name, boost::shared_ptr< FEMethod > fe_ptr)
ForcesAndSourcesCore::UserDataOperator * getRawPtrOpCalculateStress< 2, LARGE_STRAIN >(MoFEM::Interface &m_field, boost::shared_ptr< CommonData > common_data_ptr, boost::shared_ptr< ClosestPointProjection > cp_ptr, bool calc_lhs)
ForcesAndSourcesCore::UserDataOperator * getRawPtrOpCalculateStress< 3, LARGE_STRAIN >(MoFEM::Interface &m_field, boost::shared_ptr< CommonData > common_data_ptr, boost::shared_ptr< ClosestPointProjection > cp_ptr, bool calc_lhs)
MoFEMErrorCode opFactoryDomainUpdate< 3 >(MoFEM::Interface &m_field, Pip &pip, std::string block_name, boost::shared_ptr< CommonData > common_data_ptr, boost::shared_ptr< ClosestPointProjection > cp_ptr)
Push operators to update history variables.
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
VectorShallowArrayAdaptor< double > VectorAdaptor
Definition Types.hpp:115
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
auto getVectorAdaptor(T1 ptr, const size_t n)
Get Vector adaptor.
Definition Templates.hpp:49
decltype(GetFTensor2SymmetricFromMatImpl< Tensor_Dim, S, DL, M >::get(std::declval< M & >(), 0, 0)) GetFTensor2SymmetricFromMatType
decltype(GetFTensor4DdgFromMatImpl< Tensor_Dim01, Tensor_Dim23, S, DL, M >::get(std::declval< M & >(), 0, 0)) GetFTensor4DdgFromMatType
constexpr IntegrationType I
FTensor::Index< 'm', 3 > m
static FTensor::Tensor2_symmetric< FTensor::CursorPtr< double *, 6 >, 3 > getFTensor2SymmetricDiffBase(DataForcesAndSourcesCore::EntData &data, MatrixDouble &storage, const bool b_bar, const int nb_integration_pts, double *w_ptr, FTensor::Number< 2 >)
boost::shared_ptr< CommonData > commonDataPtr
MoFEMErrorCode setTagsData(const EntityHandle tet, const int nb_gauss_pts, const int nb_internal_variables)
boost::shared_ptr< ClosestPointProjection > cpPtr
OpCalculateStressImpl(MoFEM::Interface &m_field, boost::shared_ptr< CommonData > common_data_ptr, boost::shared_ptr< ClosestPointProjection > cp_ptr, bool calc_lhs)
MoFEMErrorCode doWork(int side, EntityType type, DataForcesAndSourcesCore::EntData &data) override
boost::shared_ptr< CommonData > commonDataPtr
OpUpdate(boost::shared_ptr< CommonData > common_data_ptr)
MoFEMErrorCode doWork(int side, EntityType type, DataForcesAndSourcesCore::EntData &data)
MoFEMErrorCode postProcess(TS ts)
boost::shared_ptr< FEMethod > fePtr
TSUpdateImpl(std::string fe_name, boost::shared_ptr< FEMethod > fe_ptr)
Update internal fluxes (update history variables)
virtual moab::Interface & get_moab()=0
Deprecated interface functions.
structure to get information from mofem into EntitiesFieldData
@ CTX_SNESNONE
No specific SNES context.