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 1: 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, double *scd,
7 double *rpl, double *ddsddt, double *drplde, double *drpldt, double *stran, double *dstran,
8 double *time, double *dtime, double *temp, double *dtemp, double *predef, double *dpred,
9 char *cmname, int *ndi, int *nshr, int *ntens, int *nstatv, double *props, int *nprops,
10 double *coords, double *drot, double *pnewdt, double *celent, double *dfgrd0,
11 double *dfgrd1, int *noel, int *npt, int *layer, int *kspt, int *jstep, int *kinc,
12):
13 cdef double E, nu, lam, G
14 E, nu = props[0], props[1]
15 lam = E * nu / ((1.0 + nu) * (1.0 - 2.0 * nu))
16 G = E / (2.0 * (1.0 + nu))
17
18 cdef int i, j
19 for i in range(3):
20 for j in range(3):
21 ddsdde[6 * i + j] = lam
22 ddsdde[6 * i + i] += 2.0 * G
23 ddsdde[6 * (i + 3) + (i + 3)] = G
24 for i in range(6):
25 for j in range(6):
26 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, double *scd,
7 double *rpl, double *ddsddt, double *drplde, double *drpldt, double *stran, double *dstran,
8 double *time, double *dtime, double *temp, double *dtemp, double *predef, double *dpred,
9 char *cmname, int *ndi, int *nshr, int *ntens, int *nstatv, double *props, int *nprops,
10 double *coords, double *drot, double *pnewdt, double *celent, double *dfgrd0,
11 double *dfgrd1, int *noel, int *npt, int *layer, int *kspt, int *jstep, int *kinc,
12)