# Implementing UMAT using shared library

**URL:** https://calculix.discourse.group/t/implementing-umat-using-shared-library/2441
**Category:** Uncategorized
**Created:** [October 16, 2024, 8:05pm UTC](https://calculix.discourse.group/t/implementing-umat-using-shared-library/2441 "2024-10-16T20:05:48Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![bhanups1991](https://yyz2.discourse-cdn.com/free1/user_avatar/calculix.discourse.group/bhanups1991/32/287_2.png) [@bhanups1991](https://calculix.discourse.group/u/bhanups1991)
#### Post date: [October 16, 2024, 8:05pm UTC](https://calculix.discourse.group/t/implementing-umat-using-shared-library/2441/1 "2024-10-16T20:05:48Z")

</div>

Hi

I am trying to use a UMAT (attached) in calculix as a shared library.  
I followed the procedure given in calculix documentation but the solution doesn’t proceed (please check bottom of terminal screenshot).

Here’s what I did:

1. Assigned **UMAT** as the name of the subroutine inside the file **UJ2PLASEMP.f**
2. Compiled **UJ2PLASEMP.f** using: **abaqus make library=UJ2PLASEMP.f**
3. This resulted in 2 files: **UJ2PLASEMP-std.o** and **libstandardU.so**
4. I renamed the latter file to **libUJ2PLASEMP.so**
5. In the input file, I set the material name to: **@UJ2PLASEMP\_UMAT**
6. Submitted the job on the terminal

Can you please help me with this?  
All files are uploaded to this [folder](https://iitbacin-my.sharepoint.com/:f:/g/personal/bhanups1991_iitb_ac_in/EurbUUJlcHZFtaoldKDgDOoBOGFDDdhr356-uEAGR1A9Yw?e=nQduSm)

Thanks  
Bhanu

Terminal screenshot:

 ![image](https://global.discourse-cdn.com/free1/uploads/calculix/original/2X/8/810cdd8084f79762066f2e7970df3dbd723f2f04.png)

---

<div class="post-metadata">

### Author: ![jbr](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@jbr](https://calculix.discourse.group/u/jbr)
#### Post date: [October 17, 2024, 11:44pm UTC](https://calculix.discourse.group/t/implementing-umat-using-shared-library/2441/2 "2024-10-17T23:44:35Z")

</div>

It would be best if you compiled everything using the same compilers. I’m not sure if Abaqus does something different internally to create the libs. I haven’t tried it this way, to be honest, but it appears to be problematic just by thinking about it.

---

<div class="post-metadata">

### Author: ![bhanups1991](https://yyz2.discourse-cdn.com/free1/user_avatar/calculix.discourse.group/bhanups1991/32/287_2.png) [@bhanups1991](https://calculix.discourse.group/u/bhanups1991)
#### Post date: [October 18, 2024, 5:34am UTC](https://calculix.discourse.group/t/implementing-umat-using-shared-library/2441/3 "2024-10-18T05:34:20Z")

</div>

Thank you for your reply.  
I just checked the compiler in the environment file of ABAQUS. It is “ **gfortran** ”.  
And while compiling CalculiX, in the Makefile, the FC variable (Fortran compiler) was also set to “ **gfortran** ”.

I have uploaded two new files to the same [folder](https://iitbacin-my.sharepoint.com/:f:/g/personal/bhanups1991_iitb_ac_in/EurbUUJlcHZFtaoldKDgDOoBOGFDDdhr356-uEAGR1A9Yw?e=nQduSm):  
File from abaqus directory mentioning Fortran compiler: **lin86\_64.env**  
CalculiX Makefile: **Makefile**

Based on these, can you please tell me if I need to modify the ABAQUS env file?

But otherwise, is the sequence of steps I have taken alright?  
I mean could it be a syntax issue because of inconsistent names for the function, library, and material, which prevents CalculiX from reading the UMAT.

Thanks  
Bhanu

---

<div class="post-metadata">

### Author: ![jbr](https://avatars.discourse-cdn.com/v4/letter/j/ecccb3/32.png) [@jbr](https://calculix.discourse.group/u/jbr)
#### Post date: [October 19, 2024, 2:49pm UTC](https://calculix.discourse.group/t/implementing-umat-using-shared-library/2441/4 "2024-10-19T14:49:59Z")

</div>

Why don’t you use the umat thru the Abaqus umats and recompile ccx? It is a much cleaner approach and you will know exactly what is the problem because it won’t compile

---

<div class="post-metadata">

### Author: ![johanngil](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@johanngil](https://calculix.discourse.group/u/johanngil)
#### Post date: [October 19, 2024, 3:42pm UTC](https://calculix.discourse.group/t/implementing-umat-using-shared-library/2441/5 "2024-10-19T15:42:31Z")

</div>

In your Makefile I don’t see the compiler option  
-DCALCULIX\_EXTERNAL\_BEHAVIOURS\_SUPPORT  
which seems to be needed to link UMAT related dynamic linked libraries to ccx. Try to compile the entire code with this option. Thank you!

---

<div class="post-metadata">

### Author: ![rsmith](https://yyz2.discourse-cdn.com/free1/user_avatar/calculix.discourse.group/rsmith/32/1684_2.png) [@rsmith](https://calculix.discourse.group/u/rsmith)
#### Post date: [October 23, 2024, 12:16am UTC](https://calculix.discourse.group/t/implementing-umat-using-shared-library/2441/6 "2024-10-23T00:16:52Z")

</div>

> [@johanngil](#):
>
> In your Makefile I don’t see the compiler option  
> -DCALCULIX\_EXTERNAL\_BEHAVIOURS\_SUPPORT

It would be also a good idea to also add the option  
`-DCALCULIX_EXTERNAL_BEHAVIOUR_DEBUG`. That gives extra information about what is going on.  
See the source code file `external.c` in the ccx source distribution.

---

<div class="post-metadata">

### Author: ![rsmith](https://yyz2.discourse-cdn.com/free1/user_avatar/calculix.discourse.group/rsmith/32/1684_2.png) [@rsmith](https://calculix.discourse.group/u/rsmith)
#### Post date: [October 23, 2024, 12:58am UTC](https://calculix.discourse.group/t/implementing-umat-using-shared-library/2441/7 "2024-10-23T00:58:07Z")

</div>

Neither the `Makefile` nor the `lnx86_64.env` are usable as-is.

The Makefile is for building CalculiX itself.  
The Python script `lnx86_64.env` defines some useful commands but doesn’t execute them.

You should be able to build a shared library from a single file like this:

```auto
gfortran -shared -O2 -fPIC -o libUJ2PLASEMP.so UJ2PLASEMP.f 

```

Note that this currently fails because a needed include file is not in your folder:

```auto
> gfortran -shared -O2 UJ2PLASEMP.f -o libUJ2PLASEMP.so -fPIC
UJ2PLASEMP.f:18:0:

   18 | INCLUDE 'ABA_PARAM.INC'
      | 
Fatal Error: Cannot open included file 'ABA_PARAM.INC'
compilation terminated.

```

**Note** : The file `aba_param.inc` can be found [here](https://github.com/jpsferreira/UMAT-ABAQUS/blob/master/aba_param.inc); don’t forget to rename to uppercase.

With ABA\_PARAM.INC available, the compilation works, and the shared library contains the external symbol for umat (checked on a FreeBSD UNIX machine):

```auto
nm ./libUJ2PLASEMP.so | grep ' T '
0000000000001884 T _fini
00000000000006d0 T _init
0000000000000860 T umat_

```

If I understand the CalculiX manual correctly, the material name for the user material should indeed be `@UJ2PLASEMP_UMAT`.

Note that you should rebuild CalculiX with the option to load shared libraries, as @johanngil explained.
