v0.16.3
Loading...
Searching...
No Matches
UmatInterface.hpp
Go to the documentation of this file.
1/** \file UmatInterface.hpp
2 * \brief UmatInterface
3 *
4 * This file defines the UmatInterface base class, which provides
5 * an interface for integrating Umat material models with MoFEM.
6 *
7 * \ingroup umat
8 */
9
10#ifndef UMAT_INTERFACE_HPP
11#define UMAT_INTERFACE_HPP
12
13#include <dlfcn.h>
14#include <MatOps.hpp>
15
16// Abaqus UMAT function pointer type
17// Last arg is the hidden gfortran character length for cmname
18using umat_f = void (*)(
19 double *stress, double *statev, double *ddsdde, double *sse, double *spd,
20 double *scd, double *rpl, double *ddsddt, double *drplde, double *drpldt,
21 double *stran, double *dstran, double *time, double *dtime, double *temp,
22 double *dtemp, double *predef, double *dpred, char *cmname, int *ndi,
23 int *nshr, int *ntens, int *nstatv, double *props, int *nprops,
24 double *coords, double *drot, double *pnewdt, double *celent,
25 double *dfgrd0, double *dfgrd1, int *noel, int *npt, int *layer, int *kspt,
26 int *kstep, int *kinc, std::size_t cmname_len);
27
28namespace MoFEM {
29
30template <int MODEL_TYPE> struct UmatInterface {
31
32 static constexpr int DIM = (MODEL_TYPE == MatOps::MODEL_3D ||
33 MODEL_TYPE == MatOps::MODEL_AXISYMMETRIC) ? 3 : 2;
34
35 static constexpr int NTENS = (MODEL_TYPE == MatOps::MODEL_3D) ? 6
36 : (MODEL_TYPE == MatOps::MODEL_2D_PLANE_STRESS)
37 ? 3
38 : 4;
39
40 static constexpr int NTANGENT = NTENS * NTENS;
41
42 UmatInterface(int nstatv = 0, int nprops = 2);
43
45
46 MoFEMErrorCode initialise(const std::string &library_path = "./umat.so",
47 const std::string &material_name = "UMAT");
48
51 MoFEMErrorCode setProperties(const std::vector<double> &properties);
52 MoFEMErrorCode storeStateVar(int n_state_var,
53 const std::vector<double> &state_var_values);
54 MoFEMErrorCode setTimeData(double current_time, double time_increment);
55 MoFEMErrorCode setStepData(int step_number, int increment_number);
56
58 bool use_deformation_gradient);
59
61
63
67
68 boost::shared_ptr<MatOps::MatOpsData> matOpsDataPtr;
69
70 umat_f umat = nullptr;
71 void *handle = nullptr;
72 char filename[256] = {};
73
74 static constexpr int NDI = (MODEL_TYPE == MatOps::MODEL_3D) ? 3
75 : (MODEL_TYPE == MatOps::MODEL_2D_PLANE_STRESS)
76 ? 2
77 : 3;
78 static constexpr int NSHR = (MODEL_TYPE == MatOps::MODEL_3D) ? 3 : 1;
79
81 int noel = 1, npt = 1, layer = 1, kspt = 1, kstep = 1, kinc = 1;
82
83 std::vector<double> props;
84 std::vector<double> statev;
85
86 // Voigt stress/strain buffers
87 std::array<double, NTENS> stress{}; // Cauchy stress at end of step
88 std::array<double, NTENS> stran{}; // total strain at start of increment
89 std::array<double, NTENS> dstran{}; // strain increment
90 // Material tangent (column-major for Fortran: ddsdde[i + NTENS*j] = D(i,j))
91 std::array<double, NTANGENT> ddsdde{};
92 // Deformation gradients (finite-strain path, column-major DIM×DIM)
93 std::array<double, 9> dfgrd0{}; // F at start of increment
94 std::array<double, 9> dfgrd1{}; // F at end of increment
95 std::array<double, 9> drot{};
96
97 double ddsddt[6];
98 double drplde[6];
99 double coords[3] = {};
100 char cmname[80];
101 double time[2] = {};
102 double dtime = 0.0;
103 double temp = 0.0, dtemp = 0.0;
104 std::vector<double> predef{0.0};
105 std::vector<double> dpred{0.0};
106 double pnewdt = 1.0, celent = 0.0;
107 double sse = 0.0, spd = 0.0, scd = 0.0, rpl = 0.0, drpldt = 0.0;
108};
109
110} // namespace MoFEM
111
112#endif // UMAT_INTERFACE_HPP
void(*)(double *stress, double *statev, double *ddsdde, double *sse, double *spd, double *scd, double *rpl, double *ddsddt, double *drplde, double *drpldt, double *stran, double *dstran, double *time, double *dtime, double *temp, double *dtemp, double *predef, double *dpred, char *cmname, int *ndi, int *nshr, int *ntens, int *nstatv, double *props, int *nprops, double *coords, double *drot, double *pnewdt, double *celent, double *dfgrd0, double *dfgrd1, int *noel, int *npt, int *layer, int *kspt, int *kstep, int *kinc, std::size_t cmname_len) umat_f
@ F
@ MODEL_AXISYMMETRIC
Definition MatOps.hpp:196
@ MODEL_3D
Definition MatOps.hpp:193
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
void temp(int x, int y=10)
Definition simple.cpp:4
static constexpr int NTENS
static constexpr int NSHR
MoFEMErrorCode setStepData(int step_number, int increment_number)
static constexpr int NDI
std::array< double, NTENS > stran
std::array< double, 9 > dfgrd1
MoFEMErrorCode initialise(const std::string &library_path="./umat.so", const std::string &material_name="UMAT")
std::array< double, NTENS > stress
MoFEMErrorCode setTimeData(double current_time, double time_increment)
MoFEMErrorCode getCauchyTangentTensor(MatrixDouble &cauchy_tangent) const
MoFEMErrorCode setIdentityRotationIncrement()
MoFEMErrorCode setStrainIncrementFromDeformationGradient()
MoFEMErrorCode setProperties(const std::vector< double > &properties)
boost::shared_ptr< MatOps::MatOpsData > matOpsDataPtr
static constexpr int DIM
std::vector< double > predef
MoFEMErrorCode callUmat()
std::vector< double > statev
std::vector< double > props
MoFEMErrorCode storeStateVar(int n_state_var, const std::vector< double > &state_var_values)
std::array< double, NTANGENT > ddsdde
MoFEMErrorCode setDeformationGradient(const MatrixDouble &grad, bool use_deformation_gradient)
MoFEMErrorCode setIdentityDeformationGradient()
std::vector< double > dpred
MoFEMErrorCode getCauchyStressTensor(MatrixDouble &sigma) const
static constexpr int NTANGENT
std::array< double, 9 > dfgrd0
std::array< double, NTENS > dstran
std::array< double, 9 > drot
MoFEMErrorCode getDeformationGradient(MatrixDouble &F) const