v0.16.3
Loading...
Searching...
No Matches
MatAmentumUmat.cpp
Go to the documentation of this file.
1#include <MoFEM.hpp>
2
3using namespace MoFEM;
4
5#include "MatAmentumUmat.hpp"
6#include "MatUmatImpl.hpp"
7
8namespace MatOps {
9
10static constexpr PetscReal AMENTUM_SHUTDOWN_STEP_LEN = 1e-7;
11static constexpr PetscReal AMENTUM_SHUTDOWN_TIME_TOL = 1e-12;
12
13static MoFEMErrorCode
14getShutdownTimesFromOptions(std::vector<PetscReal> &shutdown_times_vec) {
16
17 shutdown_times_vec.clear();
18
19 PetscInt n = 128;
20 PetscBool flg = PETSC_FALSE;
21 PetscReal shutdown_times[128];
22 CHKERR PetscOptionsGetRealArray(NULL, NULL, "-shutdown_times", shutdown_times,
23 &n, &flg);
24 if (flg && n > 0)
25 shutdown_times_vec.assign(shutdown_times, shutdown_times + n);
26
27 std::stable_sort(shutdown_times_vec.begin(), shutdown_times_vec.end());
28
30}
31
33
35
36 std::vector<int> getStep(const double time) {
37
38 auto equiv_step = TimeScale::getScale(time);
39 auto step_before = static_cast<int>(std::floor(equiv_step));
40 auto step_after = static_cast<int>(std::ceil(equiv_step));
41 std::vector<int> step_times = {step_before, step_after};
42 return step_times;
43 }
44};
45
46template <int DIM, int MODEL_TYPE>
47struct MatAmentumUmatImpl : public MatUmatImpl<DIM, MODEL_TYPE> {
49 using Base::Base;
50
52
53 double debugTag = 0.0;
54 static constexpr auto IRRA_TAG_NAME = "AMENTUM_FIELD_IRRA";
55 static constexpr auto PREDEF_TEMP_TAG_NAME = "AMENTUM_FIELD_PREDEF_TEMP";
56 static constexpr auto CORR_TAG_NAME = "AMENTUM_FIELD_CORR";
57 static constexpr auto TEMP_TAG_NAME = "AMENTUM_TEMP";
58 static constexpr auto DTEMP_TAG_NAME = "AMENTUM_DTEMP";
59 static constexpr auto PIOLA_TAG_NAME = "FIRST_PIOLA_TAG";
60 static constexpr int CTE0R_PROP_INDEX = 10;
61
63 const double *&young_modulus,
64 double &poisson_ratio,
65 const double *endpoint_modulus) const {
67 const auto entity = fe_ptr->getFEEntityHandle();
68 const auto *properties = &this->defaultMaterialParameters;
69 for (const auto &[range, values] : Base::paramVecByRange)
70 if (range.find(entity) != range.end()) {
71 properties = &values;
72 break;
73 }
74 // Fortran PRATIO = PROPS(5), E = STATEV(8).
75 if (properties->size() < 5)
76 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
77 "Amentum elastic properties require PROPS(5)");
78 poisson_ratio = (*properties)[4];
79 if (!std::isfinite(poisson_ratio) || poisson_ratio <= -1. ||
80 poisson_ratio >= .5)
81 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
82 "Invalid Amentum elastic Poisson ratio %g", poisson_ratio);
83
84 young_modulus = endpoint_modulus;
85 if (young_modulus) {
86 for (int gg = 0; gg != nb_gauss_pts; ++gg)
87 if (!std::isfinite(young_modulus[gg]) || young_modulus[gg] <= 0.)
88 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
89 "Invalid converged Amentum modulus at point %d", gg);
91 }
92 const auto state_tags = Base::matOpsDataPtr->getStateTags();
93 const auto name = Base::getStateVariableTagName(7);
94 const auto state =
95 std::find_if(state_tags.begin(), state_tags.end(),
96 [&](const auto &entry) { return entry.name == name; });
97 if (state == state_tags.end() || state->numComponents != 1)
98 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
99 "Amentum elastic modulus requires scalar UMAT_STATEV_7");
100 const void *values = nullptr;
101 int size = 0;
102 const auto result = Base::mField->get_moab().tag_get_by_ptr(
103 state->tag, &entity, 1, &values, &size);
104 if (result == MB_TAG_NOT_FOUND)
107 if (!values || !size)
109 if (size != nb_gauss_pts)
110 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
111 "Amentum elastic modulus does not match volume quadrature");
112 young_modulus = static_cast<const double *>(values);
113 for (int gg = 0; gg != nb_gauss_pts; ++gg)
114 if (!std::isfinite(young_modulus[gg]) || young_modulus[gg] <= 0.)
115 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
116 "Invalid Amentum elastic modulus %g at point %d",
117 young_modulus[gg], gg);
119 }
120
121 MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr = nullptr) override {
123 CHKERR Base::getOptions(m_field_ptr);
124
126
127 char props_file[PETSC_MAX_PATH_LEN] = "amentum_umat_props.inc";
128 PetscOptionsBegin(PETSC_COMM_WORLD, "umat_", "", "none");
129 CHKERR PetscOptionsString("-props_file", "Path to UMAT properties file", "",
130 props_file, props_file, sizeof(props_file),
131 PETSC_NULLPTR);
132 CHKERR PetscOptionsBool("-subtract_thermal_strain",
133 "Subtract isotropic thermal strain before UMAT", "",
135 PETSC_NULLPTR);
136 CHKERR PetscOptionsScalar(
137 "-thermal_reference_temp", "Reference temperature for thermal strain",
138 "", thermalReferenceTemp, &thermalReferenceTemp, PETSC_NULLPTR);
139 PetscOptionsEnd();
140
141 std::ifstream file(props_file);
142 if (!file.is_open()) {
143 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
144 "Could not open UMAT properties file %s", props_file);
145 }
146
147 std::vector<double> props;
148 std::string line;
149 while (std::getline(file, line)) {
150 const auto equal_pos = line.find('=');
151 if (equal_pos == std::string::npos)
152 continue;
153
154 std::istringstream value_stream(line.substr(equal_pos + 1));
155 double value = 0.0;
156 if (!(value_stream >> value)) {
157 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
158 "Could not read UMAT property value from line: %s",
159 line.c_str());
160 }
161 std::string trailing;
162 if (value_stream >> trailing) {
163 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
164 "Unexpected text after UMAT property value in line: %s",
165 line.c_str());
166 }
167
168 props.push_back(value);
169 }
170
171 if (props.size() !=
172 static_cast<std::size_t>(Base::numberMaterialProperties)) {
173 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
174 "UMAT properties file %s has %d values, expected %d", props_file,
175 static_cast<int>(props.size()), Base::numberMaterialProperties);
176 }
177
179 for (auto &range_and_parameters : Base::A::paramVecByRange)
180 range_and_parameters.second = Base::defaultMaterialParameters;
181
185 for (int i = 0; i < Base::numberMaterialProperties; ++i) {
187 }
188
189 Base::umatInterfacePtr->predef.assign(5, 0.0);
190 Base::umatInterfacePtr->dpred.assign(5, 0.0);
191
193 boost::make_shared<AgingFpyTimeScale>("aging_fpy_history.txt");
195
197 MOFEM_TAG_AND_LOG("WORLD", Sev::inform, "Amentum Umat")
198 << " subtracting thermal strain with CTE0R = "
200 << " reference_temp = " << thermalReferenceTemp;
201 }
202
204 }
205
214
216 createOp(boost::shared_ptr<PhysicalEquations> physical_ptr, bool eval_stress,
217 bool eval_tangent, bool update) override {
218 return Base::createOp(physical_ptr, eval_stress, eval_tangent, update);
219 }
220
221 MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity,
222 int gg) override {
224 CHKERR Base::evaluateVariable(tag, entity, gg);
226 }
227
228 MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg) override {
230 CHKERR Base::updateState(tag, entity, gg);
231 CHKERR this->storeCurrentFieldVariables(entity, gg);
233 }
234
235 MoFEMErrorCode storeCurrentFieldVariables(EntityHandle entity, int gg);
237 MoFEMErrorCode loadPredef(EntityHandle entity, int gg) override;
239
240protected:
242 MoFEMErrorCode evaluateFieldVariables(EntityHandle entity,
243 const VectorDouble &v_shape, double time,
244 double &irra, double &temp, double &corr);
245 bool isShutdownTime(PetscReal time_offset) const;
246
247 boost::shared_ptr<AgingFpyTimeScale> stepScalingPtr;
248 std::vector<PetscReal> shutdownTimes;
249 PetscBool subtractThermalStrain = PETSC_TRUE;
250 PetscReal thermalReferenceTemp = 20.0;
251};
252
253template <int DIM, int MODEL_TYPE>
255 MoFEM::Interface &m_field) {
257 CHKERR Base::A::matOpsDataPtr->bindStateTag(m_field, IRRA_TAG_NAME, 1);
258 CHKERR Base::A::matOpsDataPtr->bindStateTag(m_field, PREDEF_TEMP_TAG_NAME, 1);
259 CHKERR Base::A::matOpsDataPtr->bindStateTag(m_field, CORR_TAG_NAME, 1);
260 CHKERR Base::A::matOpsDataPtr->bindStateTag(m_field, TEMP_TAG_NAME, 1);
261 CHKERR Base::A::matOpsDataPtr->bindStateTag(m_field, DTEMP_TAG_NAME, 1);
262 CHKERR Base::A::matOpsDataPtr->bindStateTag(m_field, PIOLA_TAG_NAME,
263 DIM * DIM);
265}
266
267template <int DIM, int MODEL_TYPE>
269 int gg, VectorDouble &v_shape) {
271
272 auto mat_ops_data_ptr = Base::A::matOpsDataPtr;
273 auto umat_data_ptr =
274 boost::dynamic_pointer_cast<UMatOpData>(mat_ops_data_ptr->getUserDataPtr());
275 if (!umat_data_ptr || !umat_data_ptr->rawOpPtr) {
276 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
277 "Amentum UMAT needs the active material operator");
278 }
279 auto raw_op_ptr = umat_data_ptr->rawOpPtr;
280 const auto &gauss_pts = raw_op_ptr->getGaussPts();
281 const auto entity_type = raw_op_ptr->getFEType();
282 const int nb_gauss_pts = gauss_pts.size2();
283 if (gg < 0 || gg >= nb_gauss_pts) {
284 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
285 "Invalid Amentum UMAT integration point %d", gg);
286 }
287
288 // Shape values at gg follow the corner-node connectivity ordering.
289 switch (entity_type) {
290 case MBTET:
291 v_shape.resize(4, false);
292 CHKERR Tools::shapeFunMBTET(v_shape.data().data(), &gauss_pts(0, gg),
293 &gauss_pts(1, gg), &gauss_pts(2, gg), 1);
294 break;
295 case MBHEX: {
296 v_shape.resize(8, false);
297 const double ksi = gauss_pts(0, gg);
298 const double eta = gauss_pts(1, gg);
299 const double zeta = gauss_pts(2, gg);
300 v_shape[0] = N_MBHEX0(ksi, eta, zeta);
301 v_shape[1] = N_MBHEX1(ksi, eta, zeta);
302 v_shape[2] = N_MBHEX2(ksi, eta, zeta);
303 v_shape[3] = N_MBHEX3(ksi, eta, zeta);
304 v_shape[4] = N_MBHEX4(ksi, eta, zeta);
305 v_shape[5] = N_MBHEX5(ksi, eta, zeta);
306 v_shape[6] = N_MBHEX6(ksi, eta, zeta);
307 v_shape[7] = N_MBHEX7(ksi, eta, zeta);
308 break;
309 }
310 default:
311 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
312 "Amentum UMAT shape functions not implemented for entity type %d",
313 entity_type);
314 }
315
317}
318
319template <int DIM, int MODEL_TYPE>
321 EntityHandle entity, const VectorDouble &v_shape, double time, double &irra,
322 double &temp, double &corr) {
324
325 if (!Base::mField) {
326 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
327 "Amentum UMAT needs MoFEM interface to read MOAB tags");
328 }
329
330 if (!stepScalingPtr) {
331 SETERRQ(PETSC_COMM_SELF, MOFEM_OPERATION_UNSUCCESSFUL,
332 "Time scaling object is not initialized for Amentum UMAT");
333 }
334
335 auto &moab = Base::mField->get_moab();
336 const EntityHandle *conn = nullptr;
337 int num_nodes = 0;
338 CHKERR moab.get_connectivity(entity, conn, num_nodes, true);
339 if (num_nodes != v_shape.size()) {
340 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
341 "Amentum UMAT connectivity does not match the shape functions");
342 }
343
344 auto get_nodal_tag_values = [&](const char *tag_name,
345 VectorDouble &v_nodal_values) {
347 Tag tag = 0;
348 const auto tag_error = moab.tag_get_handle(tag_name, tag);
349 if (tag_error != MB_SUCCESS) {
350 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
351 "Required Amentum UMAT tag '%s' not found. Check "
352 "aging_fpy_history.txt and the projected tag mesh.",
353 tag_name);
354 }
355 int tag_length = 0;
356 DataType tag_type;
357 CHKERR moab.tag_get_length(tag, tag_length);
358 CHKERR moab.tag_get_data_type(tag, tag_type);
359 if (tag_length != 1 || tag_type != MB_TYPE_DOUBLE) {
360 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
361 "Amentum UMAT tag '%s' must contain one double per node",
362 tag_name);
363 }
364 v_nodal_values.resize(num_nodes, false);
365 CHKERR moab.tag_get_data(tag, conn, num_nodes, v_nodal_values.data().data());
367 };
368
369 auto evaluate_at_gauss_point = [&](const VectorDouble &v_nodal_values) {
370 return inner_prod(v_shape, v_nodal_values);
371 };
372
373 auto make_step_tag_name = [&](const char *prefix, int step) {
374 return (boost::format("%s_%d") % prefix % step).str();
375 };
376
377 auto load_step_tags = [&](int step, double &irra, double &temp,
378 double &corr) {
380 VectorDouble v_irra, v_temp, v_corr;
381 CHKERR get_nodal_tag_values(
382 make_step_tag_name("MED_IRRA_ALLIRRA", step).c_str(), v_irra);
383 CHKERR get_nodal_tag_values(
384 make_step_tag_name("MED_TEMP_ALLNEUT", step).c_str(), v_temp);
385 CHKERR get_nodal_tag_values(
386 make_step_tag_name("MED_CORR_ALLNEUT", step).c_str(), v_corr);
387 irra = evaluate_at_gauss_point(v_irra);
388 temp = evaluate_at_gauss_point(v_temp);
389 corr = evaluate_at_gauss_point(v_corr);
391 };
392
393 auto interpolate_predef_at_equiv_step = [&](double equiv_step, double &irra,
394 double &temp, double &corr) {
395 const int step_before = static_cast<int>(std::floor(equiv_step));
396 const int step_after = static_cast<int>(std::ceil(equiv_step));
397 double irra_b = 0.0, temp_b = 0.0, corr_b = 0.0;
398 double irra_a = 0.0, temp_a = 0.0, corr_a = 0.0;
399 CHKERR load_step_tags(step_before, irra_b, temp_b, corr_b);
400 CHKERR load_step_tags(step_after, irra_a, temp_a, corr_a);
401
402 const double alpha =
403 (step_after != step_before)
404 ? (equiv_step - step_before) / (step_after - step_before)
405 : 0.0;
406
407 irra = irra_b + alpha * (irra_a - irra_b);
408 temp = temp_b + alpha * (temp_a - temp_b);
409 corr = corr_b + alpha * (corr_a - corr_b);
410
411 return 0;
412 };
413
414 const double equiv_step = stepScalingPtr->TimeScale::getScale(time);
415 CHKERR interpolate_predef_at_equiv_step(equiv_step, irra, temp, corr);
416
418}
419
420template <int DIM, int MODEL_TYPE>
422 PetscReal time_offset) const {
423 const PetscReal shutdown_time = Base::currentTime - time_offset;
424 const auto time_it = std::lower_bound(
425 shutdownTimes.begin(), shutdownTimes.end(),
426 shutdown_time - AMENTUM_SHUTDOWN_TIME_TOL);
427 return time_it != shutdownTimes.end() &&
428 PetscAbsReal(shutdown_time - *time_it) < AMENTUM_SHUTDOWN_TIME_TOL;
429}
430
431template <int DIM, int MODEL_TYPE>
435
436 VectorDouble v_shape;
437 CHKERR getFieldShapeFunctions(gg, v_shape);
438
439 auto &umat = *Base::umatInterfacePtr;
440 umat.predef.assign(5, 0.0);
441 umat.dpred.assign(5, 0.0);
442 umat.temp = 20.0;
443 umat.dtemp = 0.0;
444
445 double current_irra = 0.0, current_predef_temp = 0.0, current_corr = 0.0;
446 CHKERR evaluateFieldVariables(entity, v_shape, Base::currentTime,
447 current_irra, current_predef_temp, current_corr);
448
449 double prev_irra = 0.0, prev_predef_temp = 0.0, prev_corr = 0.0;
450 double prev_temp = 0.0;
451
452 PetscReal prev_time = Base::currentTime - Base::currentTimeIncrement;
453 CHKERR evaluateFieldVariables(entity, v_shape, prev_time, prev_irra,
454 prev_predef_temp, prev_corr);
455 prev_temp = prev_predef_temp;
456
457 double prev_irra_test = 0.0, prev_predef_temp_test = 0.0,
458 prev_corr_test = 0.0;
459 double prev_temp_test = 0.0;
460 double debug_time_test = 0.0, debug_dt_test = 0.0, debug_step_test = 0.0;
461 auto get_previous_scalar_tag = [&](const char *tag_name, double &value) {
463 auto state_ptr =
464 Base::A::matOpsDataPtr->getStateDataPtr(tag_name, entity, gg);
465 value = (*state_ptr)(0, 0);
467 };
468
469 if (Base::currentTime == 0) {
470 prev_temp = 20.0;
471 prev_predef_temp = 20.0;
472 }
473
474 umat.predef[2] = prev_irra;
475 umat.predef[3] = prev_predef_temp;
476 umat.predef[4] = prev_corr;
477
478 umat.dpred[0] = 0.0;
479 umat.dpred[1] = 0.0;
480
481 umat.dpred[2] = current_irra - prev_irra;
482 // umat.dpred[3] = current_predef_temp - prev_predef_temp;
483 umat.dpred[4] = current_corr - prev_corr;
484
485 const bool shutdown_step =
486 isShutdownTime(AMENTUM_SHUTDOWN_STEP_LEN);
487 const bool restore_step =
488 isShutdownTime(2 * AMENTUM_SHUTDOWN_STEP_LEN);
489
490 if (shutdown_step) {
491 current_predef_temp = 20.;
492 // Cooling is already committed during iterations at the same physical age.
493 if (PetscAbsReal(Base::currentTimeIncrement) < AMENTUM_SHUTDOWN_TIME_TOL) {
494 prev_temp = current_predef_temp;
495 prev_predef_temp = current_predef_temp;
496 umat.predef[3] = prev_predef_temp;
497 }
498 } else if (restore_step) {
499 CHKERR get_previous_scalar_tag(PREDEF_TEMP_TAG_NAME, prev_temp);
500 prev_predef_temp = prev_temp;
501 umat.predef[3] = prev_predef_temp;
502 }
503
504 umat.temp = prev_temp;
505 umat.dpred[3] = current_predef_temp - prev_predef_temp;
506 umat.dtemp = current_predef_temp - prev_temp;
507 debugTag = prev_temp;
508
509 CHKERR removeThermalStrain();
510
512}
513
514template <int DIM, int MODEL_TYPE>
517
518 if (!subtractThermalStrain)
520
521 auto &umat = *Base::umatInterfacePtr;
522 const double thermal_strain_alpha =
523 Base::currentMaterialParameters[CTE0R_PROP_INDEX];
524 const double previous_thermal_strain =
525 thermal_strain_alpha * (umat.temp - thermalReferenceTemp);
526 const double thermal_strain_increment = thermal_strain_alpha * umat.dtemp;
527
528 for (int ii = 0; ii != Base::UmatInterfaceType::NDI; ++ii) {
529 umat.stran[ii] -= previous_thermal_strain;
530 umat.dstran[ii] -= thermal_strain_increment;
531 }
532
534}
535
536template <int DIM, int MODEL_TYPE>
538 EntityHandle entity, int gg) {
540
541 VectorDouble v_shape;
542 CHKERR getFieldShapeFunctions(gg, v_shape);
543 double current_irra = 0.0, current_predef_temp = 0.0, current_corr = 0.0;
544 CHKERR evaluateFieldVariables(entity, v_shape, Base::currentTime,
545 current_irra, current_predef_temp, current_corr);
546 if (isShutdownTime(AMENTUM_SHUTDOWN_STEP_LEN))
547 current_predef_temp = 20.0;
548
549 auto &umat = *Base::umatInterfacePtr;
550
551 auto set_scalar_tag = [&](const char *tag_name, double value) {
553 auto state_ptr =
554 Base::A::matOpsDataPtr->getStateDataPtr(tag_name, entity, gg);
555 (*state_ptr)(0, 0) = value;
557 };
558
559 CHKERR set_scalar_tag(IRRA_TAG_NAME, current_irra);
560 CHKERR set_scalar_tag(PREDEF_TEMP_TAG_NAME, current_predef_temp);
561 CHKERR set_scalar_tag(CORR_TAG_NAME, current_corr);
562 CHKERR set_scalar_tag(TEMP_TAG_NAME, umat.temp);
563 CHKERR set_scalar_tag(DTEMP_TAG_NAME, umat.dtemp);
564
565 // auto piola_ptr = Base::A::matOpsDataPtr->getDependentDataPtr("P");
566 auto piola_ptr = Base::A::matOpsDataPtr->getStateDataPtr(
567 Base::STRESS_TAG_NAME, entity, gg);
568
569 auto piola_state_ptr =
570 Base::A::matOpsDataPtr->getStateDataPtr(PIOLA_TAG_NAME, entity, gg);
571 constexpr int voigt_map[3][3] = {{0, 3, 4}, {3, 1, 5}, {4, 5, 2}};
572
573 for (int i = 0; i < DIM; ++i) {
574 for (int j = 0; j < DIM; ++j) {
575 (*piola_state_ptr)(i *DIM + j, 0) = (*piola_ptr)(voigt_map[i][j], 0);
576 }
577 }
578
580}
581
582template <>
583boost::shared_ptr<PhysicalEquations>
585 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
586 return boost::make_shared<MatAmentumUmatImpl<3, MODEL_3D>>(mat_ops_data_ptr,
587 tag);
588}
589
590template <>
591boost::shared_ptr<PhysicalEquations>
593 boost::shared_ptr<MatOpsData> mat_ops_data_ptr, int tag) {
594 return boost::make_shared<MatAmentumUmatImpl<2, MODEL_2D_PLANE_STRAIN>>(
595 mat_ops_data_ptr, tag);
596}
597
599 boost::shared_ptr<PhysicalEquations> material, AmentumTimeSource source) {
601 if (auto umat = boost::dynamic_pointer_cast<MatAmentumUmatImpl<3, MODEL_3D>>(
602 material))
603 umat->timeSource = std::move(source);
604 else if (auto umat = boost::dynamic_pointer_cast<
606 umat->timeSource = std::move(source);
607 else
608 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
609 "Physical time source requires an Amentum UMAT material");
611}
612
614 boost::shared_ptr<PhysicalEquations> physics_ptr, FEMethod *fe_ptr,
615 int nb_gauss_pts, const double *&young_modulus, double &poisson_ratio,
616 const double *endpoint_modulus) {
618 if (auto material =
619 boost::dynamic_pointer_cast<MatAmentumUmatImpl<3, MODEL_3D>>(
620 physics_ptr)) {
621 CHKERR material->readElasticProperties(fe_ptr, nb_gauss_pts, young_modulus,
622 poisson_ratio, endpoint_modulus);
623 } else if (auto material = boost::dynamic_pointer_cast<
625 CHKERR material->readElasticProperties(fe_ptr, nb_gauss_pts, young_modulus,
626 poisson_ratio, endpoint_modulus);
627 } else {
628 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
629 "Selected material does not supply Amentum elastic properties");
630 }
632}
633
634} // namespace MatOps
635
636/** \brief Custom TSAdaptivity in MoFEM for Amentum Umat
637 *
638 * \code
639 * CHKERR TSAdaptRegister(TSADAPTAMENTUM, TSAdaptCreateAmentum);
640 * TSAdapt adapt;
641 * CHKERR TSGetAdapt(solver, &adapt);
642 * CHKERR TSAdaptSetType(adapt, TSADAPTAMENTUM);
643 * \endcode
644 *
645 */
647
648 std::vector<PetscReal> shutdownTimes;
649 PetscBool restoreAfterShutdown = PETSC_FALSE;
650 PetscBool rampUpAfterShutdown = PETSC_FALSE;
651 PetscReal regularStepLen = .5;
652 double alpha = .75; //< step reduction if divergence
653 double gamma = .5; //< adaptivity exponent
654 int desiredIt = 6; //< desired number of iterations
655 PetscBool offApat = PETSC_FALSE;
656 PetscBool fixedStepLen = PETSC_FALSE;
657};
658
659static std::string formatShutdownTimes(const std::vector<PetscReal> &times) {
660 std::ostringstream ss;
661 ss << "[";
662 for (auto it = times.begin(); it != times.end(); ++it) {
663 if (it != times.begin())
664 ss << ", ";
665 ss << *it;
666 }
667 ss << "]";
668 return ss.str();
669}
670
671static std::string formatNextShutdownTime(const std::vector<PetscReal> &times) {
672 if (times.empty())
673 return "none";
674
675 std::ostringstream ss;
676 ss << times.front();
677 return ss.str();
678}
679
680static PetscErrorCode readAmentumOptions(TSAdapt adapt) {
682 auto &data = *static_cast<TSAdaptAmentum *>(adapt->data);
683 const char *prefix = nullptr;
684 CHKERR PetscObjectGetOptionsPrefix(reinterpret_cast<PetscObject>(adapt),
685 &prefix);
686 data.regularStepLen = .5;
687 data.alpha = .75;
688 data.gamma = .5;
689 data.desiredIt = 6;
690 data.offApat = PETSC_FALSE;
691 data.fixedStepLen = PETSC_FALSE;
693
694 CHKERR PetscOptionsGetScalar(prefix, "-ts_amentum_adapt_alpha", &data.alpha,
695 PETSC_NULLPTR);
696 CHKERR PetscOptionsGetScalar(prefix, "-ts_amentum_adapt_gamma", &data.gamma,
697 PETSC_NULLPTR);
698 CHKERR PetscOptionsGetInt(prefix, "-ts_amentum_adapt_desired_it", &data.desiredIt,
699 PETSC_NULLPTR);
700 CHKERR PetscOptionsGetBool(prefix, "-ts_amentum_adapt_off", &data.offApat,
701 PETSC_NULLPTR);
702 CHKERR PetscOptionsGetBool(prefix, "-ts_amentum_adapt_fixed_step_len",
703 &data.fixedStepLen, PETSC_NULLPTR);
704 CHKERR PetscOptionsGetReal(nullptr, prefix, "-ts_adapt_dt_min", &data.regularStepLen,
705 PETSC_NULLPTR);
706 if (!(data.alpha > 0 && data.alpha < 1) ||
707 !std::isfinite(data.gamma) || data.gamma < 0 || data.desiredIt <= 0 ||
708 !std::isfinite(data.regularStepLen) || data.regularStepLen <= 0)
709 SETERRQ(PetscObjectComm(reinterpret_cast<PetscObject>(adapt)),
710 MOFEM_INVALID_DATA, "Invalid Amentum time-step options");
711
712 MOFEM_LOG("TSWORLD", Sev::inform)
713 << "TS adaptivity: alpha = " << data.alpha << ", gamma = " << data.gamma
714 << ", desiredIt = " << data.desiredIt << ", offAdapt = " << data.offApat
715 << ", fixedStepLen = " << data.fixedStepLen
716 << ", regularStepLen = " << data.regularStepLen
717 << ", shutdownTimes = " << formatShutdownTimes(data.shutdownTimes)
718 << ", nextShutdownTime = " << formatNextShutdownTime(data.shutdownTimes);
720}
721
722static PetscErrorCode TSAdaptSetFromOptionsAmentum(TSAdapt adapt,
723 PetscOptionItems *options) {
725 // PETSc passes the parent TS options block; TSGetAdapt does not inherit its
726 // object prefix. Retain that prefix on the adaptor for subsequent resets.
727 CHKERR TSAdaptSetOptionsPrefix(adapt, options->prefix);
730}
731
732// The accepted and rejected paths share the step-size rule. Only accepted
733// scheduled intervals advance the shutdown state in TSAdaptChooseAmentum.
734static PetscErrorCode chooseAmentumStepSize(TSAdapt adapt, TS ts, PetscReal h,
735 PetscReal *next_h) {
737 auto ts_adapt_amentum = static_cast<TSAdaptAmentum *>(adapt->data);
738 *next_h = h;
739 if (ts_adapt_amentum->offApat) {
740 CHKERR TSGetTimeStep(ts, next_h);
741 } else {
742
743 SNES snes;
744 CHKERR TSGetSNES(ts, &snes);
745
746 SNESConvergedReason reason;
747 CHKERR SNESGetConvergedReason(snes, &reason);
748
749 int it;
750 CHKERR SNESGetIterationNumber(snes, &it);
751
752 if (reason < 0) {
753 h *= ts_adapt_amentum->alpha;
754 *next_h = h;
756 "TSWORLD", Sev::warning,
757 "\tDiverged set step length: it = %d, h = %3.4g set h = %3.4g \n", it,
758 h, *next_h);
759 } else if (reason > 0) {
760 if (ts_adapt_amentum->fixedStepLen) {
761 *next_h = PetscClipInterval(ts_adapt_amentum->regularStepLen,
762 adapt->dt_min, adapt->dt_max);
763 } else {
764 h *= pow((static_cast<double>(ts_adapt_amentum->desiredIt) /
765 static_cast<double>(it + 1)),
766 static_cast<double>(ts_adapt_amentum->gamma));
767 *next_h = PetscClipInterval(h, adapt->dt_min, adapt->dt_max);
768 }
770 "TSWORLD", Sev::inform,
771 "\tConverged set step length: it = %d, h = %3.4g set h = %3.4g \n",
772 it, h, *next_h);
773 }
774 }
775
777}
778
779PetscErrorCode TSAdaptChooseAmentumRejected(TSAdapt adapt, TS ts, PetscReal h,
780 PetscReal *next_h) {
782 PetscBool amentum = PETSC_FALSE;
783 CHKERR PetscObjectTypeCompare(reinterpret_cast<PetscObject>(adapt),
784 TSADAPTAMENTUM, &amentum);
785 if (!amentum)
786 SETERRQ(PetscObjectComm(reinterpret_cast<PetscObject>(adapt)),
787 MOFEM_INVALID_DATA, "Rejected physical step requires Amentum adaptivity");
788 CHKERR chooseAmentumStepSize(adapt, ts, h, next_h);
790}
791
792PetscErrorCode TSAdaptChooseAmentum(TSAdapt adapt, TS ts, PetscReal h,
793 PetscInt *next_sc, PetscReal *next_h,
794 PetscBool *accept, PetscReal *wlte,
795 PetscReal *wltea, PetscReal *wlter) {
797
798 auto ts_adapt_amentum = static_cast<TSAdaptAmentum *>(adapt->data);
799 const PetscReal accepted_step_len = h;
800
801 *next_sc = 0; /* Reuse the same order scheme */
802 *wlte = -1; /* Weighted local truncation error was not evaluated */
803 *wltea = -1; /* Weighted absolute local truncation error is not used */
804 *wlter = -1; /* Weighted relative local truncation error is not used */
805
806 *accept = PETSC_TRUE;
807 *next_h = h; /* Reuse the old step */
808
809 CHKERR chooseAmentumStepSize(adapt, ts, h, next_h);
810
811 PetscReal current_t;
812 CHKERR TSGetTime(ts, &current_t);
813
814 const PetscReal accepted_t = current_t + accepted_step_len;
815
816 if (ts_adapt_amentum->restoreAfterShutdown) {
818 ts_adapt_amentum->restoreAfterShutdown = PETSC_FALSE;
819 ts_adapt_amentum->rampUpAfterShutdown = PETSC_TRUE;
820 MOFEM_LOG_C("TSWORLD", Sev::inform,
821 "\tShutdown step complete: t = %3.12g set restore h = %3.4g\n",
822 accepted_t, *next_h);
823 } else if (ts_adapt_amentum->rampUpAfterShutdown) {
824 *next_h = ts_adapt_amentum->regularStepLen;
825 ts_adapt_amentum->rampUpAfterShutdown = PETSC_FALSE;
826 while (!ts_adapt_amentum->shutdownTimes.empty() &&
827 accepted_t >= ts_adapt_amentum->shutdownTimes.front() -
829 ts_adapt_amentum->shutdownTimes.erase(
830 ts_adapt_amentum->shutdownTimes.begin());
831 }
832 MOFEM_LOG_C("TSWORLD", Sev::inform,
833 "\tField restore step complete: t = %3.12g set h = %3.4g\n",
834 accepted_t, *next_h);
835 } else if (!ts_adapt_amentum->shutdownTimes.empty()) {
836 const PetscReal nextShutdownTime = ts_adapt_amentum->shutdownTimes.front();
837
838 if (PetscAbsReal(accepted_t - nextShutdownTime) <=
841 ts_adapt_amentum->restoreAfterShutdown = PETSC_TRUE;
842 MOFEM_LOG_C("TSWORLD", Sev::inform,
843 "\tShutdown step after t = %3.12g set h = %3.4g \n",
844 accepted_t, *next_h);
845 } else {
846 const PetscReal next_t = accepted_t + *next_h;
847 if (accepted_t < nextShutdownTime && next_t >= nextShutdownTime) {
848 *next_h = nextShutdownTime - accepted_t;
849 MOFEM_LOG_C("TSWORLD", Sev::inform,
850 "\tClip step to shutdown: t = %3.12g shutdown = "
851 "%3.12g set h = %3.4g \n",
852 accepted_t, nextShutdownTime, *next_h);
853 }
854 }
855 }
856
858}
859
860PetscErrorCode TSAdaptResetAmentum(TSAdapt adapt) {
861 PetscFunctionBegin;
862 if (adapt->data) {
863 *static_cast<TSAdaptAmentum *>(adapt->data) = TSAdaptAmentum();
864 PetscCall(readAmentumOptions(adapt));
865 }
866 PetscFunctionReturn(0);
867}
868
869PetscErrorCode TSAdaptDestroyAmentum(TSAdapt adapt) {
871 delete static_cast<TSAdaptAmentum *>(adapt->data);
872 adapt->data = nullptr;
874}
875
876PetscErrorCode TSAdaptCreateAmentum(TSAdapt adapt) {
877 PetscFunctionBegin;
878 adapt->data = new TSAdaptAmentum();
879 adapt->ops->choose = TSAdaptChooseAmentum;
880 adapt->ops->setfromoptions = TSAdaptSetFromOptionsAmentum;
881 adapt->ops->reset = TSAdaptResetAmentum;
882 adapt->ops->destroy = TSAdaptDestroyAmentum;
883 PetscFunctionReturn(0);
884}
TetMeshData result
std::function< bool(size_t)> accept
Definition CGALTools.cpp:61
int h
Corner vertex and its two front neighbours.
std::vector< int > source
std::vector< int > size
Tag tag
#define MOFEM_LOG_C(channel, severity, format,...)
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
PetscErrorCode TSAdaptChooseAmentumRejected(TSAdapt adapt, TS ts, PetscReal h, PetscReal *next_h)
static std::string formatShutdownTimes(const std::vector< PetscReal > &times)
PetscErrorCode TSAdaptCreateAmentum(TSAdapt adapt)
PetscErrorCode TSAdaptChooseAmentum(TSAdapt adapt, TS ts, PetscReal h, PetscInt *next_sc, PetscReal *next_h, PetscBool *accept, PetscReal *wlte, PetscReal *wltea, PetscReal *wlter)
static std::string formatNextShutdownTime(const std::vector< PetscReal > &times)
PetscErrorCode TSAdaptResetAmentum(TSAdapt adapt)
static PetscErrorCode readAmentumOptions(TSAdapt adapt)
static PetscErrorCode chooseAmentumStepSize(TSAdapt adapt, TS ts, PetscReal h, PetscReal *next_h)
PetscErrorCode TSAdaptDestroyAmentum(TSAdapt adapt)
static PetscErrorCode TSAdaptSetFromOptionsAmentum(TSAdapt adapt, PetscOptionItems *options)
Amentum-specific UMAT registration surface.
#define TSADAPTAMENTUM
Shared UMAT implementation details for built-in and user-defined UMATs.
PyGILState_STATE state
Definition SDFPython.cpp:13
It it
Definition Schur.cpp:2568
SmartPetscObj< Vec > values
std::string name
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_INVALID_DATA
Definition definitions.h:36
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define N_MBHEX7(x, y, z)
Definition fem_tools.h:78
#define N_MBHEX3(x, y, z)
Definition fem_tools.h:74
#define N_MBHEX5(x, y, z)
Definition fem_tools.h:76
#define N_MBHEX4(x, y, z)
Definition fem_tools.h:75
#define N_MBHEX0(x, y, z)
Definition fem_tools.h:71
#define N_MBHEX6(x, y, z)
Definition fem_tools.h:77
#define N_MBHEX2(x, y, z)
Definition fem_tools.h:73
#define N_MBHEX1(x, y, z)
Definition fem_tools.h:72
double eta
#define MOFEM_LOG(channel, severity)
Log.
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'j', 3 > j
MoFEMErrorCode setAmentumTimeSource(boost::shared_ptr< PhysicalEquations > material, AmentumTimeSource source)
MoFEMErrorCode getAmentumElasticProperties(boost::shared_ptr< PhysicalEquations > physics_ptr, FEMethod *fe_ptr, int nb_gauss_pts, const double *&young_modulus, double &poisson_ratio, const double *endpoint_modulus)
static MoFEMErrorCode getShutdownTimesFromOptions(std::vector< PetscReal > &shutdown_times_vec)
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< AMENTUM_UMAT, MODEL_2D_PLANE_STRAIN >(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
std::function< void(PetscReal &, PetscReal &, PetscInt &)> AmentumTimeSource
static constexpr PetscReal AMENTUM_SHUTDOWN_TIME_TOL
static constexpr PetscReal AMENTUM_SHUTDOWN_STEP_LEN
boost::shared_ptr< PhysicalEquations > createMatOpsPhysicalEquationsPtr< AMENTUM_UMAT, MODEL_3D >(boost::shared_ptr< MatOpsData > mat_ops_data_ptr, int tag)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
PetscErrorCode PetscOptionsGetScalar(PetscOptions *, const char pre[], const char name[], PetscScalar *dval, PetscBool *set)
PetscErrorCode PetscOptionsGetRealArray(PetscOptions *, const char pre[], const char name[], PetscReal dval[], PetscInt *nmax, PetscBool *set)
double young_modulus
Young modulus.
Definition plastic.cpp:126
double poisson_ratio
Poisson ratio.
Definition plastic.cpp:127
double zeta
Viscous hardening.
Definition plastic.cpp:131
void temp(int x, int y=10)
Definition simple.cpp:4
std::vector< int > getStep(const double time)
MoFEMErrorCode loadPredef(EntityHandle entity, int gg) override
static constexpr auto DTEMP_TAG_NAME
static constexpr auto CORR_TAG_NAME
boost::shared_ptr< AgingFpyTimeScale > stepScalingPtr
static constexpr auto IRRA_TAG_NAME
static constexpr int CTE0R_PROP_INDEX
MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override
MoFEMErrorCode updateState(int tag, EntityHandle entity, int gg) override
MoFEMErrorCode getFieldShapeFunctions(int gg, VectorDouble &v_shape)
MoFEMErrorCode storeCurrentFieldVariables(EntityHandle entity, int gg)
MoFEMErrorCode bindAuxiliaryStateTags(MoFEM::Interface &m_field) override
static constexpr auto PREDEF_TEMP_TAG_NAME
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
MoFEMErrorCode evaluateVariable(int tag, EntityHandle entity, int gg) override
std::vector< PetscReal > shutdownTimes
MoFEMErrorCode readElasticProperties(FEMethod *fe_ptr, int nb_gauss_pts, const double *&young_modulus, double &poisson_ratio, const double *endpoint_modulus) const
MoFEMErrorCode removeThermalStrain()
static constexpr auto TEMP_TAG_NAME
ForcesAndSourcesCore::UserDataOperator * createOp(boost::shared_ptr< PhysicalEquations > physical_ptr, bool eval_stress, bool eval_tangent, bool update) override
bool isShutdownTime(PetscReal time_offset) const
MoFEMErrorCode evaluateFieldVariables(EntityHandle entity, const VectorDouble &v_shape, double time, double &irra, double &temp, double &corr)
static constexpr auto PIOLA_TAG_NAME
static std::string getStateVariableTagName(const int index)
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
ForcesAndSourcesCore::UserDataOperator * createOp(boost::shared_ptr< PhysicalEquations > physical_ptr, bool eval_stress, bool eval_tangent, bool update) override
Definition MatUmat.cpp:21
std::vector< double > defaultMaterialParameters
std::vector< double > currentMaterialParameters
std::unique_ptr< UmatInterfaceType > umatInterfacePtr
MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override
MoFEMErrorCode evaluateVariable(int, EntityHandle entity, int gg) override
MoFEMErrorCode updateState(int, EntityHandle entity, int gg) override
MoFEM::Interface * mField
PetscReal currentTimeIncrement
std::vector< std::pair< Range, std::vector< double > > > paramVecByRange
Definition MatOps.hpp:199
boost::shared_ptr< MatOpsData > matOpsDataPtr
Definition MatOps.hpp:201
virtual moab::Interface & get_moab()=0
Deprecated interface functions.
Structure for user loop methods on finite elements.
EntityHandle getFEEntityHandle() const
Get the entity handle of the current finite element.
Force scale operator for reading two columns.
double getScale(const double time)
Get scaling at a given time.
TimeScale(std::string file_name="", bool error_if_file_not_given=false, ScalingFun def_scaling_fun=[](double time) { return time;})
TimeScale constructor.
static MoFEMErrorCode shapeFunMBTET(double *shape, const double *ksi, const double *eta, const double *zeta, const double nb)
Calculate shape functions on tetrahedron.
Definition Tools.hpp:809
Custom TSAdaptivity in MoFEM for Amentum Umat.
PetscBool restoreAfterShutdown
PetscReal regularStepLen
PetscBool rampUpAfterShutdown
std::vector< PetscReal > shutdownTimes
subroutine umat(stress, statev, ddsdde, sse, spd, scd, rpl, ddsddt, drplde, drpldt, stran, dstran, time, dtime, temp, dtemp, predef, dpred, cmname, ndi, nshr, ntens, nstatv, props, nprops, coords, drot, pnewdt, celent, dfgrd0, dfgrd1, noel, npt, layer, kspt, kstep, kinc)