v0.16.0
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) ? 3 : 2;
33
34 static constexpr int NTENS = (MODEL_TYPE == MatOps::MODEL_3D) ? 6
35 : (MODEL_TYPE == MatOps::MODEL_2D_PLANE_STRESS)
36 ? 3
37 : 4;
38
39 static constexpr int NTANGENT = NTENS * NTENS;
40
41 UmatInterface(int nstatv = 0, int nprops = 2);
42
44
45 MoFEMErrorCode initialise(const std::string &library_path = "./umat.so",
46 const std::string &material_name = "UMAT");
47
49 MoFEMErrorCode setProperties(const std::vector<double> &properties);
50 MoFEMErrorCode storeStateVar(int n_state_var,
51 const std::vector<double> &state_var_values);
52 MoFEMErrorCode setTimeData(double current_time, double time_increment);
53 MoFEMErrorCode setStepData(int step_number, int increment_number);
54
56 bool use_deformation_gradient);
57
59
61
65
66 boost::shared_ptr<MatOps::MatOpsData> matOpsDataPtr;
67
68 umat_f umat = nullptr;
69 void *handle = nullptr;
70 char filename[256] = {};
71
72 static constexpr int NDI = (MODEL_TYPE == MatOps::MODEL_3D) ? 3
73 : (MODEL_TYPE == MatOps::MODEL_2D_PLANE_STRESS)
74 ? 2
75 : 3;
76 static constexpr int NSHR = (MODEL_TYPE == MatOps::MODEL_3D) ? 3 : 1;
77
79 int noel = 1, npt = 1, layer = 1, kspt = 1, kstep = 1, kinc = 1;
80
81 std::vector<double> props;
82 std::vector<double> statev;
83
84 // Voigt stress/strain buffers
85 std::array<double, NTENS> stress{}; // Cauchy stress at end of step
86 std::array<double, NTENS> stran{}; // total strain at start of increment
87 std::array<double, NTENS> dstran{}; // strain increment
88 // Material tangent (column-major for Fortran: ddsdde[i + NTENS*j] = D(i,j))
89 std::array<double, NTANGENT> ddsdde{};
90 // Deformation gradients (finite-strain path, column-major DIM×DIM)
91 std::array<double, 9> dfgrd0{}; // F at start of increment
92 std::array<double, 9> dfgrd1{}; // F at end of increment
93 std::array<double, 9> drot{};
94
95 double ddsddt[6];
96 double drplde[6];
97 double coords[3] = {};
98 char cmname[80];
99 double time[2] = {};
100 double dtime = 0.0;
101 double temp = 0.0, dtemp = 0.0;
102 std::vector<double> predef{0.0};
103 std::vector<double> dpred{0.0};
104 double pnewdt = 1.0, celent = 0.0;
105 double sse = 0.0, spd = 0.0, scd = 0.0, rpl = 0.0, drpldt = 0.0;
106};
107
108} // namespace MoFEM
109
110#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_3D
Definition MatOps.hpp:181
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 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