6#ifndef MAT_UMAT_IMPL_HPP
7#define MAT_UMAT_IMPL_HPP
25template <
int DIM,
int MODEL_TYPE>
31 EntityHandle entity,
int gg)
override {
35 "UMAT interface is not initialised");
39 umat.noel =
static_cast<int>(entity);
50 CHKERR umat.setStrainIncrementFromDeformationGradient();
60 boost::shared_ptr<MatOpsData> mat_ops_data_ptr)
override {
63 auto set_stress_from_umat_cauchy = [&]() {
66 auto t_P = getFTensor2FromPtr<DIM, DIM>(
67 mat_ops_data_ptr->getDependentDataPtr(
"P")->data().data());
72 for (
int i = 0;
i != DIM; ++
i)
73 for (
int Jidx = 0; Jidx != DIM; ++Jidx)
74 t_P(
i, Jidx) = sigma(
i, Jidx);
79 CHKERR set_stress_from_umat_cauchy();
85 boost::shared_ptr<MatOpsData> mat_ops_data_ptr)
override {
88 auto set_tangent_from_umat_cauchy = [&]() {
91 auto t_dP = getFTensor4FromPtr<DIM, DIM, DIM, DIM>(
92 mat_ops_data_ptr->getDependentDerivativesDataPtr(
"P_dF")
97 CHKERR umat.getCauchyTangentTensor(d_sigma_d_eps);
99 for (
int i = 0;
i != DIM; ++
i)
100 for (
int Jidx = 0; Jidx != DIM; ++Jidx)
101 for (
int m = 0;
m != DIM; ++
m)
102 for (
int N = 0;
N != DIM; ++
N)
109 CHKERR set_tangent_from_umat_cauchy();
114template <
int DIM,
int MODEL_TYPE>
120 EntityHandle entity,
int gg)
override {
130 boost::shared_ptr<MatOpsData> mat_ops_data_ptr)
override {
133 (void)mat_ops_data_ptr;
139 boost::shared_ptr<MatOpsData> mat_ops_data_ptr)
override {
142 (void)mat_ops_data_ptr;
147template <
int DIM,
int MODEL_TYPE>
153 EntityHandle entity,
int gg)
override {
163 boost::shared_ptr<MatOpsData> mat_ops_data_ptr)
override {
166 (void)mat_ops_data_ptr;
172 boost::shared_ptr<MatOpsData> mat_ops_data_ptr)
override {
175 (void)mat_ops_data_ptr;
180template <
int DIM,
int MODEL_TYPE>
182 using MatPiolaResponse::MatPiolaResponse;
192 tag_name += std::to_string(
index);
197 createOp(boost::shared_ptr<PhysicalEquations> physical_ptr,
bool eval_stress,
198 bool eval_tangent,
bool update)
override;
207 char umat_library[PETSC_MAX_PATH_LEN] = {};
209 sizeof(umat_library) - 1);
210 char umat_name[80] =
"UMAT";
211 PetscInt nstatev = 0;
213 const char *list_strain_type[] = {
"small",
"hencky",
"finite"};
215 PetscOptionsBegin(PETSC_COMM_WORLD,
"umat_",
"",
"none");
216 CHKERR PetscOptionsString(
"-library",
"Path to UMAT shared library",
"",
217 umat_library, umat_library,
sizeof(umat_library),
219 CHKERR PetscOptionsString(
"-name",
"UMAT material name",
"", umat_name,
220 umat_name,
sizeof(umat_name), PETSC_NULLPTR);
221 CHKERR PetscOptionsInt(
"-nstatev",
"Number of UMAT state variables",
"",
222 nstatev, &nstatev, PETSC_NULLPTR);
223 CHKERR PetscOptionsInt(
"-nprops",
"Number of UMAT material properties",
"",
224 nprops, &nprops, PETSC_NULLPTR);
225 CHKERR PetscOptionsScalar(
"-young_modulus",
"Default first property",
"",
227 CHKERR PetscOptionsScalar(
"-poisson_ratio",
"Default second property",
"",
230 "-strain_type",
"Strain type",
"", list_strain_type, 3,
231 list_strain_type[choice_strain], &choice_strain, PETSC_NULLPTR);
238 strainHandler = std::make_unique<SmallStrainHandler<DIM, MODEL_TYPE>>();
241 strainHandler = std::make_unique<HenckyStrainHandler<DIM, MODEL_TYPE>>();
244 strainHandler = std::make_unique<FiniteStrainHandler<DIM, MODEL_TYPE>>();
248 "Unsupported UMAT strain type");
253 "UMAT requires a positive number of properties");
258 "UMAT requires a non-negative number of state variables");
282 std::string block_name =
"MAT_UMAT";
285 std::regex((boost::format(
"%s(.*)") % block_name).str()))) {
286 std::vector<double> block_data;
287 CHKERR m->getAttributes(block_data);
289 if (block_data.empty())
293 "MAT_UMAT block requires at least %d attributes", nprops);
296 auto get_block_ents = [&]() {
299 m->meshset, ents,
true),
300 "can not get block entities");
306 std::vector<double>(block_data.begin(),
309 std::ostringstream properties_stream;
310 properties_stream <<
"[";
313 properties_stream <<
", ";
314 properties_stream << block_data[ii];
316 properties_stream <<
"]";
319 << *
m <<
" properties = " << properties_stream.str();
352 if (range.find(ent) != range.end()) {
374 DIM * DIM, DIM * DIM,
false);
413 "UMAT options must be set before evaluation");
438 for (
int dd = 0; dd != 3; ++dd)
467 bool has_stored_gradient =
false;
470 const double value = (*state_ptr)(
row * DIM +
col, 0);
472 has_stored_gradient = has_stored_gradient || std::abs(value) > 0;
476 if (!has_stored_gradient) {
490 (*state_ptr)(
row *DIM +
col, 0) =
std::map< EntityHandle, int > index
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
std::vector< FieldBitNumber > row
std::vector< FieldBitNumber > col
#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 ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ MOFEM_OPERATION_UNSUCCESSFUL
@ MOFEM_DATA_INCONSISTENCY
#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 MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
FTensor::Index< 'i', SPACE_DIM > i
int umatTensorIndex(const int ii, const int jj)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
UBlasMatrix< double > MatrixDouble
implementation of Data Operators for Forces and Sources
FTensor::Index< 'm', 3 > m
MoFEMErrorCode runUmat(MatUmatImpl< DIM, MODEL_TYPE > &matUmatImpl, EntityHandle entity, int gg) override
MoFEMErrorCode convertTangent(MatUmatImpl< DIM, MODEL_TYPE > &matUmatImpl, boost::shared_ptr< MatOpsData > mat_ops_data_ptr) override
MoFEMErrorCode convertStress(MatUmatImpl< DIM, MODEL_TYPE > &matUmatImpl, boost::shared_ptr< MatOpsData > mat_ops_data_ptr) override
MoFEMErrorCode convertTangent(MatUmatImpl< DIM, MODEL_TYPE > &matUmatImpl, boost::shared_ptr< MatOpsData > mat_ops_data_ptr) override
MoFEMErrorCode runUmat(MatUmatImpl< DIM, MODEL_TYPE > &matUmatImpl, EntityHandle entity, int gg) override
MoFEMErrorCode convertStress(MatUmatImpl< DIM, MODEL_TYPE > &matUmatImpl, boost::shared_ptr< MatOpsData > mat_ops_data_ptr) override
Constitutive response expressed by first Piola stress.
static bool useDeformationGradient
Otherwise the displacement gradient is supplied and I is added.
MoFEMErrorCode storeCurrentDeformationGradient(EntityHandle entity, int gg)
MoFEMErrorCode loadPreviousStress(EntityHandle entity, int gg)
MoFEMErrorCode storeCurrentStress(EntityHandle entity, int gg)
static constexpr auto STRESS_TAG_NAME
static std::string getStateVariableTagName(const int index)
MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr) override
virtual MoFEMErrorCode recordAuxiliaryMatOpsData()
virtual MoFEMErrorCode loadPredef(EntityHandle entity, int gg)
ForcesAndSourcesCore::UserDataOperator * createOp(boost::shared_ptr< PhysicalEquations > physical_ptr, bool eval_stress, bool eval_tangent, bool update) override
std::vector< double > defaultMaterialParameters
MoFEMErrorCode recordTape() override
std::vector< double > currentMaterialParameters
std::unique_ptr< UmatInterfaceType > umatInterfacePtr
MoFEMErrorCode storeCurrentStateVariables(EntityHandle entity, int gg)
MoFEMErrorCode setParams(FEMethod *fe_ptr, int gg) override
std::vector< std::string > vStateVariableTagNames
int numberMaterialProperties
MoFEMErrorCode evaluateVariable(int, EntityHandle entity, int gg) override
static constexpr auto DFGRD0_TAG_NAME
virtual MoFEMErrorCode loadCoordinates(EntityHandle entity, int gg)
MoFEMErrorCode initialiseUmatOnDemand()
MoFEMErrorCode updateState(int, EntityHandle entity, int gg) override
static constexpr char STATEV_TAG_NAME[]
std::unique_ptr< StrainHandler< DIM, MODEL_TYPE > > strainHandler
virtual MoFEMErrorCode bindAuxiliaryStateTags(MoFEM::Interface &m_field)
MoFEMErrorCode loadPreviousDeformationGradient(EntityHandle entity, int gg)
MoFEM::Interface * mField
std::vector< double > stateVar
MoFEMErrorCode loadPreviousStateVariables(EntityHandle entity, int gg)
MoFEMErrorCode evaluateDerivatives(int, EntityHandle entity, int gg) override
PetscReal currentTimeIncrement
std::vector< std::pair< Range, std::vector< double > > > paramVecByRange
boost::shared_ptr< MatOpsData > matOpsDataPtr
MoFEMErrorCode runUmat(MatUmatImpl< DIM, MODEL_TYPE > &matUmatImpl, EntityHandle entity, int gg) override
MoFEMErrorCode convertTangent(MatUmatImpl< DIM, MODEL_TYPE > &matUmatImpl, boost::shared_ptr< MatOpsData > mat_ops_data_ptr) override
MoFEMErrorCode convertStress(MatUmatImpl< DIM, MODEL_TYPE > &matUmatImpl, boost::shared_ptr< MatOpsData > mat_ops_data_ptr) override
Deprecated interface functions.
Structure for user loop methods on finite elements.
EntityHandle getFEEntityHandle() const
Get the entity handle of the current finite element.
Interface for managing meshsets containing materials and boundary conditions.
PetscReal ts_t
Current time value.
PetscReal ts_dt
Current time step size.
PetscInt ts_step
Current time step number.
static constexpr int NTENS
static constexpr const char * DEFAULT_LIBRARY_PATH
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)