v0.16.3
Loading...
Searching...
No Matches
abaqus_450t_umat_replay.cpp
Go to the documentation of this file.
1/** \file abaqus_450t_umat_replay.cpp
2 * \brief Reproduce the 450T Abaqus sensitivity moduli at accepted endpoints.
3 */
4#include <MoFEM.hpp>
5using namespace MoFEM;
6#include <UmatInterface.hpp>
7
8#include <array>
9#include <cmath>
10#include <fstream>
11#include <sstream>
12
13namespace {
14
15struct SensitivityCase {
16 const char *name;
17 std::array<double, 5> irradiationTemp;
18 std::array<double, 4> youngModulus;
19 std::array<double, 4> p1;
20 bool checkP1;
21};
22
23// CM_Notes.xlsx: Sensitivities!A3:Q7, Sheet3!A3:U7, Sheet4!A3:U7.
24const std::array<SensitivityCase, 3> cases{{
25 {"base",
26 {20, 20, 450, 450, 450},
27 {11890, 22252.4, 21894.7, 21516.6},
28 {1, 1.5195, 1.57151, 1.57161},
29 true},
30 {"S1",
31 {20, 20, 235, 450, 450},
32 {11890, 19588, 21429.4, 21475},
33 {1, 1.33448, 1.54454, 1.57156},
34 true},
35 {"S2",
36 {20, 20, 20, 235, 450},
37 {11890, 17483.2, 19802.5, 21679.3},
38 {},
39 false},
40}};
41
42constexpr std::array<double, 5> dose{{0, 0.003, 7.25, 14.5, 21.75}};
43constexpr std::array<double, 5> timeAtStepEnd{
44 {0, 1e-6, 2.000001, 4.000001, 6.000001}};
45
46MoFEMErrorCode checkValue(double actual, double expected, double tolerance,
47 const char *quantity, const char *case_name,
48 int step) {
50 if (!std::isfinite(actual) || std::abs(actual - expected) > tolerance)
51 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID,
52 "%s step %d: %s = %.12g, Abaqus = %.12g (tolerance %.3g)",
53 case_name, step, quantity, actual, expected, tolerance);
55}
56
57MoFEMErrorCode readProperties(std::vector<double> &properties) {
59 std::ifstream file("amentum_umat_props.inc");
60 if (!file)
61 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
62 "Could not open amentum_umat_props.inc");
63 std::string line;
64 while (std::getline(file, line)) {
65 const auto equal = line.find('=');
66 if (equal == std::string::npos)
67 continue;
68 std::istringstream value(line.substr(equal + 1));
69 double parameter;
70 if (!(value >> parameter))
71 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
72 "Invalid UMAT property in %s", line.c_str());
73 properties.push_back(parameter);
74 }
75 if (properties.size() != 134)
76 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
77 "Abaqus sensitivity replay needs 134 UMAT properties");
79}
80
81MoFEMErrorCode replay(const SensitivityCase &test_case,
82 const std::vector<double> &properties) {
85 CHKERR umat.initialise("./grumat.so", "UMAT");
86 umat.props = properties;
87 umat.predef.assign(5, 0);
88 umat.dpred.assign(5, 0);
89 CHKERR umat.setIdentityDeformationGradient();
90 umat.dfgrd1 = umat.dfgrd0;
91 CHKERR umat.setIdentityRotationIncrement();
92
93 const auto interpolate = [](double start, double end, double fraction) {
94 return start + fraction * (end - start);
95 };
96
97 for (int step = 1; step != 5; ++step) {
98 const int increment_count = step == 1 ? 1 : 8;
99 for (int increment = 1; increment <= increment_count; ++increment) {
100 const double a = static_cast<double>(increment - 1) / increment_count;
101 const double b = static_cast<double>(increment) / increment_count;
102 const double start_time =
103 interpolate(timeAtStepEnd[step - 1], timeAtStepEnd[step], a);
104 const double end_time =
105 interpolate(timeAtStepEnd[step - 1], timeAtStepEnd[step], b);
106 const double start_dose = interpolate(dose[step - 1], dose[step], a);
107 const double end_dose = interpolate(dose[step - 1], dose[step], b);
108 const double start_temp = interpolate(test_case.irradiationTemp[step - 1],
109 test_case.irradiationTemp[step], a);
110 const double end_temp = interpolate(test_case.irradiationTemp[step - 1],
111 test_case.irradiationTemp[step], b);
112
113 CHKERR umat.setTimeData(end_time, end_time - start_time);
114 CHKERR umat.setStepData(step, increment);
115 CHKERR checkValue(umat.time[1], start_time, 1e-12, "TIME(2)",
116 test_case.name, step);
117 umat.temp = start_temp;
118 umat.dtemp = end_temp - start_temp;
119 umat.predef[2] = start_dose;
120 umat.predef[3] = start_temp;
121 umat.dpred[2] = end_dose - start_dose;
122 umat.dpred[3] = end_temp - start_temp;
123
124 // Match the standalone adapter's zero mechanical-strain input.
125 umat.stran.fill(0);
126 umat.dstran.fill(0);
127 for (int direction = 0; direction != 3; ++direction) {
128 umat.stran[direction] = -properties[10] * (umat.temp - 20);
129 umat.dstran[direction] = -properties[10] * umat.dtemp;
130 }
131 umat.pnewdt = 1;
132 CHKERR umat.callUmat();
133 }
134
135 const double expected_dose = step == 1 ? 0 : dose[step];
136 CHKERR checkValue(umat.statev[1], expected_dose, 1e-8, "STATEV(2) dose",
137 test_case.name, step);
138 CHKERR checkValue(umat.statev[2], test_case.irradiationTemp[step], 1e-8,
139 "STATEV(3) irradiation temperature", test_case.name,
140 step);
141 CHKERR checkValue(umat.statev[5], 1, 1e-8, "STATEV(6) weight-loss factor",
142 test_case.name, step);
143 CHKERR checkValue(umat.statev[7], test_case.youngModulus[step - 1], 0.05,
144 "STATEV(8) Young's modulus", test_case.name, step);
145 if (test_case.checkP1)
146 CHKERR checkValue(umat.statev[79], test_case.p1[step - 1], 5e-6,
147 "STATEV(80) P1", test_case.name, step);
148 if (step > 1) {
149 CHKERR checkValue(umat.statev[0], step == 2 ? 3.6235 : 3.625, 1e-8,
150 "STATEV(1) dose rate", test_case.name, step);
151 CHKERR checkValue(umat.statev[6], 0.25, 1e-12, "STATEV(7) increment",
152 test_case.name, step);
153 }
154 PetscPrintf(PETSC_COMM_WORLD,
155 "%s step %d: dose %.6g, irradiation T %.6g, E %.8g, P1 %.8g\n",
156 test_case.name, step, dose[step], umat.statev[2],
157 umat.statev[7], umat.statev[79]);
158 }
159
161}
162
163} // namespace
164
165int main(int argc, char **argv) {
166 MoFEM::Core::Initialize(&argc, &argv, nullptr, nullptr);
167 try {
168 std::vector<double> properties;
169 CHKERR readProperties(properties);
170 for (const auto &test_case : cases)
171 CHKERR replay(test_case, properties);
172 PetscPrintf(PETSC_COMM_WORLD,
173 "Abaqus 450T UMAT sensitivity replay passed\n");
174 }
177 return 0;
178}
double tolerance
Radians.
It end
Definition Schur.cpp:2568
std::string name
UmatInterface.
int main()
constexpr double a
#define CATCH_ERRORS
Catch errors.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
@ 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.
promote< T, double >::V interpolate(const Tensor0< T * > &a, const int &di, const int &dj, const int &dk, const int &i0, const int &j0, const int &k0, const double distance[3], const double conjugate[3])
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:68
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:123
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)