Examples
Below are some examples of how to use the library.
To compile the examples into an object file (.obj
) that can be used by Abaqus, you can run the following command:
abqcy compile <path-to-your-subroutine>
Example: Elastic umat
subroutine
This example shows how to write an Abaqus elastic umat
subroutine in Cython.
1cdef extern from "<aba_for_c.h>":
2 pass
3
4
5cdef extern void umat(
6 double *stress, double *statev, double *ddsdde, double *sse, double *spd,
7 double *scd, double *rpl, double *ddsddt, double *drplde, double *drpldt,
8 double *stran, double *dstran, double *time, double *dtime, double *temp,
9 double *dtemp, double *predef, double *dpred, char *cmname, int *ndi,
10 int *nshr, int *ntens, int *nstatv, double *props, int *nprops, double *coords,
11 double *drot, double *pnewdt, double *celent, double *dfgrd0, double *dfgrd1,
12 int *noel, int *npt, int *layer, int *kspt, int *jstep, int *kinc,
13):
14 cdef double E, nu, lam, G
15 E, nu = props[0], props[1]
16 lam = E * nu / ((1.0 + nu) * (1.0 - 2.0 * nu))
17 G = E / (2.0 * (1.0 + nu))
18
19 cdef int i, j
20 for i in range(3):
21 for j in range(3):
22 ddsdde[6 * i + j] = lam
23 ddsdde[6 * i + i] += 2.0 * G
24 ddsdde[6 * (i + 3) + (i + 3)] = G
25 for i in range(6):
26 for j in range(6):
27 stress[i] += ddsdde[6 * i + j] * dstran[j]
1import cython
2
3
4def umat(
5 stress, statev, ddsdde, sse, spd, scd, rpl, ddsddt, drplde, drpldt, stran, dstran,
6 time, dtime, temp, dtemp, predef, dpred, cmname, ndi, nshr, ntens, nstatv, props,
7 nprops, coords, drot, pnewdt, celent, dfgrd0, dfgrd1, noel, npt, layer, kspt,
8 jstep, kinc,
9): # fmt: skip
10 cython.declare(E=cython.double, nu=cython.double, lam=cython.double, G=cython.double)
11 E, nu = props[0], props[1]
12 lam = E * nu / ((1.0 + nu) * (1.0 - 2.0 * nu))
13 G = E / (2.0 * (1.0 + nu))
14
15 cython.declare(i=cython.int, j=cython.int)
16 for i in range(3):
17 for j in range(3):
18 ddsdde[6 * i + j] = lam
19 ddsdde[6 * i + i] += 2.0 * G
20 ddsdde[6 * (i + 3) + (i + 3)] = G
21 for i in range(6):
22 for j in range(6):
23 stress[i] += ddsdde[6 * i + j] * dstran[j]
Note
You will need to add the Cython header file (.pxd
) along with the Python file (.py
) in order to use the Cython
declarations.
1cdef extern from "<aba_for_c.h>":
2 pass
3
4
5cdef extern void umat(
6 double *stress, double *statev, double *ddsdde, double *sse, double *spd,
7 double *scd, double *rpl, double *ddsddt, double *drplde, double *drpldt,
8 double *stran, double *dstran, double *time, double *dtime, double *temp,
9 double *dtemp, double *predef, double *dpred, char *cmname, int *ndi,
10 int *nshr, int *ntens, int *nstatv, double *props, int *nprops, double *coords,
11 double *drot, double *pnewdt, double *celent, double *dfgrd0, double *dfgrd1,
12 int *noel, int *npt, int *layer, int *kspt, int *jstep, int *kinc,
13)