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